From 1f954df0d83563c0b8a4fd6745182fb956e2e803 Mon Sep 17 00:00:00 2001 From: teryhill Date: Wed, 2 Mar 2016 12:47:39 -0500 Subject: [PATCH] Removed sql-ledger, take 3. --- accounting/README.sql-ledger | 75 -- accounting/sql-ledger.conf | 80 -- accounting/ws_server.pl | 308 -------- accounting/ws_server_26.pl | 321 -------- accounting/ws_server_28.pl | 381 ---------- interface/billing/era_payments.php | 7 +- interface/billing/indigent_patients_report.php | 20 +- interface/billing/sl_eob_invoice.php | 213 +----- interface/billing/sl_eob_process.php | 74 +- interface/billing/sl_eob_search.php | 403 +--------- interface/billing/sl_receipts_report.php | 135 ---- interface/globals.php | 15 - interface/main/backup.php | 57 +- interface/patient_file/deleter.php | 22 +- interface/patient_file/front_payment.php | 56 -- interface/patient_file/history/encounters.php | 24 +- interface/patient_file/pos_checkout.php | 116 +-- interface/reports/collections_report.php | 246 +------ interface/reports/inventory_activity.php | 1 - interface/reports/receipts_by_method_report.php | 91 --- interface/reports/sales_by_item.php | 36 +- interface/reports/svc_code_financial_report.php | 7 - library/Claim.class.php | 59 +- library/invoice_summary.inc.php | 117 +-- library/sl_eob.inc.php | 928 +++++++----------------- library/sql-ledger.inc | 53 -- sl_convert.php | 345 --------- 27 files changed, 290 insertions(+), 3900 deletions(-) delete mode 100644 accounting/README.sql-ledger delete mode 100644 accounting/sql-ledger.conf delete mode 100755 accounting/ws_server.pl delete mode 100755 accounting/ws_server_26.pl delete mode 100644 accounting/ws_server_28.pl rewrite library/sl_eob.inc.php (64%) delete mode 100644 library/sql-ledger.inc delete mode 100644 sl_convert.php diff --git a/accounting/README.sql-ledger b/accounting/README.sql-ledger deleted file mode 100644 index 60e427372..000000000 --- a/accounting/README.sql-ledger +++ /dev/null @@ -1,75 +0,0 @@ - Integrating SQL-Ledger with OpenEMR - by Tekkno Genius - - -1. Install sql-ledger according to sql-ledger's instructions. Make sure it is -working before adding the support for openemr. Installation basically amounts -to untarring sql-ledger in a directory, creating an alias/virtual directory in -your web server, creating the sql-ledger user in the postgresql database, see -the sql-ledger README for the details: - - http://www.sql-ledger.org/cgi-bin/nav.pl?page=source/readme.txt&title=README - -OpenEMR configuration: - -2. Create a sql-ledger user for openemr to post as. Bring up sql-ledger in -admin mode [http://localhost/sql-ledger/admin.pl]. Login as the sql-ledger -user. Create a dataset (database) for openemr to put its data (I called mine -openemr) and used the default set of books (accounting codes). Create a user -to use this dataset. I created a user called openemr. Note, this user is not a -postgresql user, it is a sql-ledger user. You see that you need to put a user -to log into postgresql as. Here I used the default sql-ledger user. Make sure -you select the Pg (postgresql) driver. - -3.Edit the sql-ledger.conf file. Add the following to the default -sql-ledger.conf: - - $oemr_ar_acc - $oemr_cash_acc - $oemr_due_days - $oemr_username - $oemr_services_partnumber - -to the use vars section at the top - -Add the following also: - -# Some constants relevant to OpenEMR import. -# -$oemr_username = 'openemr'; # sql-ledger user to post as -$oemr_ar_acc = '1200'; # account number for accounts receivable -$oemr_cash_acc = '1060'; # account number for checking (copay deposits) - -# In SQL-Ledger you must create a services item for medical services -# before you do any OpenEMR billing. Specify its "part number" here: -# -$oemr_services_partnumber = 'MS'; - -# This is the number of days added to the OpenEMR transaction date to -# produce the invoice due date when there is insurance. This affects the -# patient portion of the outstanding balance shown in the OpenEMR patient -# summary, and of course SQL-Ledger's aging reports and statements. -# -$oemr_due_days = 40; - -Note: $oemr_username is the same user you created in step 2. - -Also note: A sample sql-ledger.conf including the above parameters is -included, however it may be incomplete from the standpoint of the current -SQL-Ledger release. - -4. Copy ws_server.pl to the sql-ledger directory if you are using SQL-Ledger -2.4.x. If you are using 2.6.x then copy ws_server_26.pl to that directory -as ws_server.pl. Alternatively you can create a suitable symbolic link in -that directory. Then, examine the resulting ws_server.pl and change the -"use lib qw" statement as indicated. - -5. Edit the openemr/interface/globals.php and put the right data for the -following variables: - -$sl_dbname = 'openemr'; // sql-ledger database name -$sl_dbuser = 'sql-ledger'; // sql-ledger database login name -$sl_dbpass = 'secret'; // sql-ledger database login password - -Note: $sl_user is a postgresql user -$sl_dbname is the dataset you created in step 2. diff --git a/accounting/sql-ledger.conf b/accounting/sql-ledger.conf deleted file mode 100644 index 5b435af6e..000000000 --- a/accounting/sql-ledger.conf +++ /dev/null @@ -1,80 +0,0 @@ -use vars qw($userspath $spool $memberfile $templates $sendmail $language $sid $latex %printer $gzip $oemr_ar_acc $oemr_cash_acc $oemr_due_days $oemr_username $oemr_services_partnumber $oemr_sales_tax $oemr_state $oemr_geo_zone); - -# path to user configuration files -$userspath = "users"; - -# spool directory for batch printing -$spool = "spool"; - -# templates base directory -$templates = "templates"; - -# member file -$memberfile = "users/members"; - -# location of sendmail -$sendmail = "| /usr/sbin/sendmail -t"; - -# set language for login and admin -$language = ""; - -# Some constants relevant to OpenEMR import. -# -$oemr_username = 'admin'; # sql-ledger user to post as -$oemr_ar_acc = '1200'; # account number for accounts receivable -$oemr_cash_acc = '1060'; # account number for checking (copay deposits) - -# In SQL-Ledger you must create a services item for medical services -# before you do any OpenEMR billing. Specify its "part number" here: -# -$oemr_services_partnumber = 'MS'; - -# This is the number of days added to the OpenEMR transaction date to -# produce the invoice due date when there is insurance. This affects the -# patient portion of the outstanding balance shown in the OpenEMR patient -# summary, and of course SQL-Ledger's aging reports and statements. -# -$oemr_due_days = 40; - -# These are for defining *only* US state sales tax for your clinic. -# This feature currently requires SQL-Ledger 2.8.x. -# -# This is the sql-ledger sales tax account number for location of clinic (from chart of accounts) -# You will need to first set up your tax rates in sql-ledger and then define the chart id here. -# I used 2310 since that is the first default chart id for taxes in sql-ledger. -# If you do not want to use this then leave $oemr_sales_tax as an empty string. -# -$oemr_sales_tax = ''; -#$oemr_sales_tax = '2310'; # Commented out by default -# -# Your state for which you need to collect sales tax, the geo_zone code is from the -# openemr mysql database of the same name. -$oemr_state = 'CA'; -$oemr_geo_zone = '12'; - -# Oracle -#$sid = "T80509"; -#$ENV{"ORACLE_HOME"} = "/usr/local/oracle"; - -# if you have latex installed set to 1 -$latex = 1; - -# available printers -%printer = ( Laser => 'lpr -Plaser', - Epson => 'lpr -PEpson', - ); - -# program to use for file compression -$gzip = "gzip -S .gz"; - -# if the server can't find gzip, latex, dvips or pdflatex, add the path -$ENV{PATH} .= ":/usr/local/bin"; - -# on mac os X using Fink's Perl libs, add the path -#$ENV{PERL5LIB} .= ":/sw/lib/perl5"; - -# DB2, Default dataset is expected to be LEDGER -#$ENV{DB2INSTANCE} = "db2inst1"; -#$ENV{DB2_HOME} = "/opt/IBM/db2/V8.1/"; - -1; diff --git a/accounting/ws_server.pl b/accounting/ws_server.pl deleted file mode 100755 index fd2978672..000000000 --- a/accounting/ws_server.pl +++ /dev/null @@ -1,308 +0,0 @@ -#!/usr/bin/perl - -###################################################################### -# This module is compatible only with SQL-Ledger version 2.4.x. -# Copy it to your SQL-Ledger installation directory as ws_server.pl. -###################################################################### - -use Frontier::Responder; -use DBI; - -###################################################################### -# IMPORTANT - modify this to point to your SQL-Ledger installation! -###################################################################### -use lib qw (/var/www/sql-ledger); - -use SL::User; -use SL::Form; -use SL::CT; -use SL::HR; -use SL::IS; -use SL::IC; -use SL::AR; - -require "sql-ledger.conf"; - -my $add_customer = \&rpc_add_customer; -my $add_salesman = \&rpc_add_employee; -my $add_invoice = \&rpc_add_invoice; -my $customer_balance = \&rpc_customer_balance; - -my $res = Frontier::Responder->new( methods => { - 'ezybiz.add_invoice' => $add_invoice, - 'ezybiz.add_salesman' => $add_salesman, - 'ezybiz.customer_balance' =>$customer_balance, - 'ezybiz.add_customer' => $add_customer -}, ); - -print $res->answer; - -sub rpc_customer_balance { - my ($post_hash) = @_; - if ($$post_hash{id} > 0 ) { - my $myconfig = new User "$memberfile", "$oemr_username"; - $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; - my $form = new Form; - $form->{title} = "AR Outstanding"; - $form->{outstanding} = "1"; - $form->{customer_id} = $$post_hash{id}; - $form->{sort} = "transdate" ; - $form->{l_due} = 1; - $form->{nextsub} = "ar_transaction"; - $form->{action} = 'Continue'; - - AR::ar_transactions("",\%$myconfig, \%$form); - - my ($paid,$amount) = 0; - - # Exclude invoices that are not yet due (i.e. waiting for insurance). - # We no longer use the due date for this; instead ar.notes identifies - # insurances used, and ar.shipvia indicates which of those are done. - # If all insurances are done, it's due. - # - foreach my $resref (@{$$form{transactions}}) { - my $inspending = 0; - foreach my $tmp ('Ins1','Ins2','Ins3') { - ++$inspending if ($$resref{notes} =~ /$tmp/ && $$resref{shipvia} !~ /$tmp/); - } - if ($inspending == 0) { - $paid += $$resref{paid}; - $amount += $$resref{amount}; - } - } - - my $retval = $amount - $paid; - return($retval); - } -} - -sub rpc_add_customer -{ - use lib '/usr/lib/perl5/site_perl/5.8.3'; - - my ($post_hash) = @_; - - #take struct of data and map to post data to create the customer, return the id - my $myconfig = new User "$memberfile", "$oemr_username"; - $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; - my $form = new Form; - $form->{name} = substr($$post_hash{'firstname'} . " " . $$post_hash{'lastname'}, 0, 64); - $form->{discount} = ""; - $form->{terms} = ""; - $form->{taxincluded} = "1"; - $form->{creditlimit} = "0"; - $form->{id} = $$post_hash{'foreign_id'}; - $form->{login} = ""; - $form->{employee} = ""; - $form->{pricegroup} = ""; - $form->{business} = ""; - $form->{language} = ""; - $form->{address1} = substr($$post_hash{'address'}, 0, 32); - $form->{address2} = substr($$post_hash{'address'}, 32, 32); - $form->{city} = substr($$post_hash{'suburb'}, 0, 32); - - if($$post_hash{'state'}){ - $form->{state} = substr($$post_hash{'state'}, 0, 32); - }else{ - $form->{state} = substr($$post_hash{'geo_zone_id'}, 0, 32); - } - $form->{zipcode} = substr($$post_hash{'postcode'}, 0, 10); - $form->{country} = ""; - $form->{contact} = ""; - $form->{phone} = substr($$post_hash{'phone1'}, 0, 20); - $form->{fax} = ""; - $form->{email} = $$post_hash{'email'}; - $form->{taxnumber} = substr($$post_hash{'ssn'}, 0, 32); - $form->{curr} = "USD"; - $form->{customernumber} = $$post_hash{'customernumber'}; - @t = localtime(time); - $dd = $t[3]; - $mm = $t[4] + 1; - $yy = $t[5] + 1900; - - $form->{startdate} = "$mm-$dd-$yy"; - - CT::save_customer('', \%$myconfig, \%$form); - my $retVal = $form->{id}; - - return($retVal); -} - -sub rpc_add_employee -{ - my ($post_hash) = @_; - my $myconfig = new User "$memberfile", "$oemr_username"; - $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; - my $form = new Form; - $form->{id} = $$post_hash{'foreign_id'}; - $form->{name} = $$post_hash{'fname'} . " " . $$post_hash{'lname'}; - $form->{sales} = $$post_hash{'authorized'}; - @t = localtime(time); - $dd = $t[3]; - $mm = $t[4] + 1; - $yy = $t[5] + 1900; - - $form->{startdate} = "$mm-$dd-$yy"; - HR::save_employee("",\%$myconfig, \%$form); - my $retVal = $form->{id}; - return($retVal); -} - -sub rpc_add_invoice -{ - my ($post_hash) = @_; - - my $myconfig = new User "$memberfile", "$oemr_username"; - $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; - my $form = new Form; - $form->{id}; - $form->{employee} = "--" . $$post_hash{'salesman'}; - $form->{customer_id} = $$post_hash{'customerid'}; - $form->{invnumber} = $$post_hash{'invoicenumber'}; - $form->{amount} = $$post_hash{'total'}; - $form->{netamount} = $$post_hash{'total'}; - $form->{notes} = $$post_hash{'notes'}; - $form->{department} = ""; - $form->{currency} = "USD"; - $form->{defaultcurrency} = "USD"; - - # This is the AR account number, needed by IS::post_invoice. - $form->{AR} = $oemr_ar_acc; - - # This will use the posting date as the billing date - @t = localtime(time); - - # $dd = $t[3]; - # $mm = $t[4] + 1; - # $yy = $t[5] + 1900; - - $form->{transdate} = sprintf("%02u-%02u-%04u", $t[4] + 1, $t[3], $t[5] + 1900); - - # This overrides the above statement to use the date of service as the - # invoice date, which should be preferable for most practices. Comment - # out the following line if you really want the billing date instead. - # - $form->{transdate} = $$post_hash{'dosdate'}; - - # If there is insurance, set a future due date so we don't bother - # the patient for a while. - # - if ($$post_hash{'payer_id'}) { - @t = localtime(60 * 60 * 24 * $oemr_due_days + time); - $form->{duedate} = sprintf("%02u-%02u-%04u", $t[4] + 1, $t[3], $t[5] + 1900); - } else { - $form->{duedate} = $form->{transdate}; - } - - # Get out if the invoice already exists. - my $trans_id = 0; - my $dbh = $form->dbconnect($myconfig); - my $query = qq|SELECT id FROM ar WHERE invnumber = ?|; - my $eth = $dbh->prepare($query) || die "Failed to prepare ar query"; - $eth->execute($$post_hash{'invoicenumber'}) || die "Failed to execute ar query"; - ($trans_id) = $eth->fetchrow_array; - $eth->finish; - - if ($trans_id) { - print STDERR "Skipping invoice $trans_id = " . $$post_hash{'invoicenumber'} . "\n"; - $dbh->disconnect; - return 0; - } - - #loop through line items and add them to invoice - my $i = 1; - my $j = 1; #this is for copays should only be one but who knows -j - my $count = 0; - my $items = $$post_hash{'items'}; - - foreach my $line_item (@$items) - { - if ($$line_item{'itemtext'} =~ /COPAY/) { - $form->{"datepaid_$j"} = $form->{transdate}; # "$mm-$dd-$yy"; - # For copays we use a dummy procedure code because it may be applicable - # to multiple procedures during the visit. - $form->{"memo_$j"} = 'Co-pay'; - # Put the payment method and check number in the source field if they are - # present (i.e. from pos_checkout.php). - if ($$line_item{'itemtext'} =~ /^COPAY:([A-Z].*)$/) { - $form->{"source_$j"} = $1; - } else { - $form->{"source_$j"} = 'Co-pay'; - } - # $form->{"paid_$j"} = abs($$line_item{'price'}); - $form->{"paid_$j"} = 0 - $$line_item{'price'}; - $form->{"AR_paid_$j"} = "$oemr_cash_acc" . "--"; - $j++; - } - else{ - $form->{"qty_$i"} = $$line_item{'qty'}; - $form->{"discount_$i"} = 0; - $form->{"sellprice_$i"} = $$line_item{'price'}; - - $form->{taxincluded} = 1; - $form->{"taxaccounts_$i"} = 0; - $form->{"income_accno_$i"} = $$line_item{'glaccountid'}; - - $form->{"id_$i"} = add_goodsandservices(\%$myconfig, \%$form, $oemr_services_partnumber, - 'Medical Services', ''); - - $form->{"description_$i"} = $$line_item{'itemtext'}; - $form->{"unit_$i"} = ''; - $form->{"serialnumber_$i"} = $$line_item{'maincode'}; - - # Save the insurance company ID as the SL project ID. This gives us a way - # to associate each invoice item with its insurance payer. The clinic will - # probably want to write some reporting software taking advantage of this. - # - $form->{"projectnumber_$i"} = "--" . $$post_hash{'payer_id'} - if ($$post_hash{'payer_id'}); - $i++; - } - } - - $dbh->disconnect; - - $form->{paidaccounts} = $j - 1; - $form->{rowcount} = $i - 1; - IS::post_invoice("", \%$myconfig, \%$form); - my $retVal = $form->{id}; - return($retVal); -} - -sub get_partid -{ - my ($myconfig, $form, $number) = @_; - my $retval = 0; - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my $query = qq|SELECT id FROM parts WHERE partnumber = ?|; - my $eth = $dbh->prepare($query) || die "Failed to create select id from parts query"; - $eth->execute($number) || die "Failed to execute select id from parts query"; - ($retval) = $eth->fetchrow_array; - $eth->finish; - $dbh->disconnect; - return($retval); -} - -sub add_goodsandservices -{ - my ($myconfig, $form, $code, $desc, $price) = @_; - my $retval = 0; - $retval = get_partid($myconfig, $form, $code); - - if($retval == 0) - { - # connect to database, turn off autocommit - my $dbh = $form->dbconnect_noauto($myconfig); - my $query = qq|insert into parts (partnumber,description,listprice,sellprice) values(?,?,?,?)|; - my $eth = $dbh->prepare($query) || die "failed to create insert into parts query" . $dbh->errstr; - $eth->execute($code,$desc,$price,$price) || die "failed to execute insert into parts query" . $dbh->errstr; - $dbh->commit || die $dbh->errstr; - $eth->finish || die "cannot finish " . $dbh->errstr; - $dbh->disconnect; - $retval = get_partid($myconfig, $form, $code); - } - - return($retval); -} diff --git a/accounting/ws_server_26.pl b/accounting/ws_server_26.pl deleted file mode 100755 index c298e0782..000000000 --- a/accounting/ws_server_26.pl +++ /dev/null @@ -1,321 +0,0 @@ -#!/usr/bin/perl - -###################################################################### -# This module is compatible only with SQL-Ledger version 2.6.x. -# Copy it to your SQL-Ledger installation directory as ws_server.pl. -###################################################################### - -use Frontier::Responder; -use DBI; - -###################################################################### -# IMPORTANT - modify this to point to your SQL-Ledger installation! -###################################################################### -use lib qw (/var/www/sql-ledger); - -use SL::User; -use SL::Form; -use SL::CT; -use SL::HR; -use SL::IS; -use SL::IC; -use SL::AA; - -require "sql-ledger.conf"; - -my $add_customer = \&rpc_add_customer; -my $add_salesman = \&rpc_add_employee; -my $add_invoice = \&rpc_add_invoice; -my $customer_balance = \&rpc_customer_balance; - -# In case we are running under Windows, do not strip carriage returns -# from POSTed data, otherwise Frontier::Responder may fail. -binmode(STDIN); - -my $res = Frontier::Responder->new( methods => { - 'ezybiz.add_invoice' => $add_invoice, - 'ezybiz.add_salesman' => $add_salesman, - 'ezybiz.customer_balance' =>$customer_balance, - 'ezybiz.add_customer' => $add_customer -}, ); - -print $res->answer; - -sub rpc_customer_balance { - my ($post_hash) = @_; - if ($$post_hash{id} > 0 ) { - my $myconfig = new User "$memberfile", "$oemr_username"; - $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; - my $form = new Form; - $form->{title} = "AR Outstanding"; - $form->{outstanding} = "1"; - $form->{customer_id} = $$post_hash{id}; - $form->{sort} = "transdate" ; - $form->{l_due} = 1; - $form->{nextsub} = "transaction"; - $form->{vc} = "customer" ; - $form->{action} = 'Continue'; - - AA::transactions("",\%$myconfig, \%$form); - - my ($paid,$amount) = 0; - - # Exclude invoices that are not yet due (i.e. waiting for insurance). - # We no longer use the due date for this; instead ar.notes identifies - # insurances used, and ar.shipvia indicates which of those are done. - # If all insurances are done, it's due. - # - foreach my $resref (@{$$form{transactions}}) { - my $inspending = 0; - foreach my $tmp ('Ins1','Ins2','Ins3') { - ++$inspending if ($$resref{notes} =~ /$tmp/ && $$resref{shipvia} !~ /$tmp/); - } - if ($inspending == 0) { - $paid += $$resref{paid}; - $amount += $$resref{amount}; - } - } - - my $retval = $amount - $paid; - return($retval); - } -} - -sub rpc_add_customer -{ - use lib '/usr/lib/perl5/site_perl/5.8.3'; - - my ($post_hash) = @_; - - #take struct of data and map to post data to create the customer, return the id - my $myconfig = new User "$memberfile", "$oemr_username"; - $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; - my $form = new Form; - $form->{name} = substr($$post_hash{'firstname'} . " " . $$post_hash{'lastname'}, 0, 64); - $form->{discount} = ""; - $form->{terms} = ""; - $form->{taxincluded} = "1"; - $form->{creditlimit} = "0"; - $form->{id} = $$post_hash{'foreign_id'}; - $form->{login} = ""; - $form->{employee} = ""; - $form->{pricegroup} = ""; - $form->{business} = ""; - $form->{language} = ""; - $form->{address1} = substr($$post_hash{'address'}, 0, 32); - $form->{address2} = substr($$post_hash{'address'}, 32, 32); - $form->{city} = substr($$post_hash{'suburb'}, 0, 32); - - if($$post_hash{'state'}){ - $form->{state} = substr($$post_hash{'state'}, 0, 32); - }else{ - $form->{state} = substr($$post_hash{'geo_zone_id'}, 0, 32); - } - $form->{zipcode} = substr($$post_hash{'postcode'}, 0, 10); - $form->{country} = ""; - $form->{contact} = ""; - $form->{phone} = substr($$post_hash{'phone1'}, 0, 20); - $form->{fax} = ""; - $form->{email} = $$post_hash{'email'}; - $form->{taxnumber} = substr($$post_hash{'ssn'}, 0, 32); - $form->{curr} = "USD"; - $form->{customernumber} = $$post_hash{'customernumber'}; - @t = localtime(time); - $dd = $t[3]; - $mm = $t[4] + 1; - $yy = $t[5] + 1900; - - $form->{startdate} = "$mm-$dd-$yy"; - - CT::save_customer('', \%$myconfig, \%$form); - my $retVal = $form->{id}; - - return($retVal); -} - -sub rpc_add_employee -{ - my ($post_hash) = @_; - my $myconfig = new User "$memberfile", "$oemr_username"; - $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; - my $form = new Form; - $form->{id} = $$post_hash{'foreign_id'}; - $form->{name} = $$post_hash{'fname'} . " " . $$post_hash{'lname'}; - $form->{sales} = $$post_hash{'authorized'}; - @t = localtime(time); - $dd = $t[3]; - $mm = $t[4] + 1; - $yy = $t[5] + 1900; - - $form->{startdate} = "$mm-$dd-$yy"; - HR::save_employee("",\%$myconfig, \%$form); - my $retVal = $form->{id}; - return($retVal); -} - -sub rpc_add_invoice -{ - my ($post_hash) = @_; - - my $myconfig = new User "$memberfile", "$oemr_username"; - $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; - my $form = new Form; - $form->{id}; - $form->{employee} = "--" . $$post_hash{'salesman'}; - $form->{customer_id} = $$post_hash{'customerid'}; - $form->{invnumber} = $$post_hash{'invoicenumber'}; - $form->{amount} = $$post_hash{'total'}; - $form->{netamount} = $$post_hash{'total'}; - $form->{notes} = $$post_hash{'notes'}; - $form->{department} = ""; - $form->{currency} = "USD"; - $form->{defaultcurrency} = "USD"; - - # This is the AR account number, needed by IS::post_invoice. - $form->{AR} = $oemr_ar_acc; - - # This will use the posting date as the billing date - @t = localtime(time); - - # $dd = $t[3]; - # $mm = $t[4] + 1; - # $yy = $t[5] + 1900; - - $form->{transdate} = sprintf("%02u-%02u-%04u", $t[4] + 1, $t[3], $t[5] + 1900); - - # This overrides the above statement to use the date of service as the - # invoice date, which should be preferable for most practices. Comment - # out the following line if you really want the billing date instead. - # - $form->{transdate} = $$post_hash{'dosdate'}; - - # If there is insurance, set a future due date so we don't bother - # the patient for a while. - # - if ($$post_hash{'payer_id'}) { - @t = localtime(60 * 60 * 24 * $oemr_due_days + time); - $form->{duedate} = sprintf("%02u-%02u-%04u", $t[4] + 1, $t[3], $t[5] + 1900); - } else { - $form->{duedate} = $form->{transdate}; - } - - # Get out if the invoice already exists. - my $trans_id = 0; - my $dbh = $form->dbconnect($myconfig); - my $query = qq|SELECT id FROM ar WHERE invnumber = ?|; - my $eth = $dbh->prepare($query) || die "Failed to prepare ar query"; - $eth->execute($$post_hash{'invoicenumber'}) || die "Failed to execute ar query"; - ($trans_id) = $eth->fetchrow_array; - $eth->finish; - - if ($trans_id) { - print STDERR "Skipping invoice $trans_id = " . $$post_hash{'invoicenumber'} . "\n"; - $dbh->disconnect; - return 0; - } - - #loop through line items and add them to invoice - my $i = 1; - my $j = 1; #this is for copays should only be one but who knows -j - my $count = 0; - my $items = $$post_hash{'items'}; - - foreach my $line_item (@$items) - { - if ($$line_item{'itemtext'} =~ /COPAY/) { - $form->{"datepaid_$j"} = $form->{transdate}; # "$mm-$dd-$yy"; - # For copays we use a dummy procedure code because it may be applicable - # to multiple procedures during the visit. - $form->{"memo_$j"} = 'Co-pay'; - # Put the payment method and check number in the source field if they are - # present (i.e. from pos_checkout.php). - if ($$line_item{'itemtext'} =~ /^COPAY:([A-Z].*)$/) { - $form->{"source_$j"} = $1; - } else { - $form->{"source_$j"} = 'Co-pay'; - } - # $form->{"paid_$j"} = abs($$line_item{'price'}); - $form->{"paid_$j"} = 0 - $$line_item{'price'}; - $form->{"AR_paid_$j"} = "$oemr_cash_acc" . "--"; - $j++; - } - else{ - my $chart_id = 0; - my $query = qq|SELECT id FROM chart WHERE accno = ?|; - my $eth = $dbh->prepare($query) || die "Failed to prepare chart query"; - $eth->execute($$line_item{'glaccountid'}) || die "Failed to execute chart query"; - ($chart_id) = $eth->fetchrow_array; - $eth->finish; - - $form->{"qty_$i"} = $$line_item{'qty'}; - $form->{"discount_$i"} = 0; - $form->{"sellprice_$i"} = $$line_item{'price'}; - - $form->{taxincluded} = 1; - $form->{"taxaccounts_$i"} = 0; - $form->{"income_accno_$i"} = $$line_item{'glaccountid'}; - $form->{"income_accno_id_$i"} = $chart_id; - - $form->{"id_$i"} = add_goodsandservices(\%$myconfig, \%$form, $oemr_services_partnumber, - 'Medical Services', ''); - - $form->{"description_$i"} = $$line_item{'itemtext'}; - $form->{"unit_$i"} = ''; - $form->{"serialnumber_$i"} = $$line_item{'maincode'}; - - # Save the insurance company ID as the SL project ID. This gives us a way - # to associate each invoice item with its insurance payer. The clinic will - # probably want to write some reporting software taking advantage of this. - # - $form->{"projectnumber_$i"} = "--" . $$post_hash{'payer_id'} - if ($$post_hash{'payer_id'}); - $i++; - } - } - - $dbh->disconnect; - - $form->{paidaccounts} = $j - 1; - $form->{rowcount} = $i - 1; - IS::post_invoice("", \%$myconfig, \%$form); - my $retVal = $form->{id}; - return($retVal); -} - -sub get_partid -{ - my ($myconfig, $form, $number) = @_; - my $retval = 0; - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my $query = qq|SELECT id FROM parts WHERE partnumber = ?|; - my $eth = $dbh->prepare($query) || die "Failed to create select id from parts query"; - $eth->execute($number) || die "Failed to execute select id from parts query"; - ($retval) = $eth->fetchrow_array; - $eth->finish; - $dbh->disconnect; - return($retval); -} - -sub add_goodsandservices -{ - my ($myconfig, $form, $code, $desc, $price) = @_; - my $retval = 0; - $retval = get_partid($myconfig, $form, $code); - - if($retval == 0) - { - # connect to database, turn off autocommit - my $dbh = $form->dbconnect_noauto($myconfig); - my $query = qq|insert into parts (partnumber,description,listprice,sellprice) values(?,?,?,?)|; - my $eth = $dbh->prepare($query) || die "failed to create insert into parts query" . $dbh->errstr; - $eth->execute($code,$desc,$price,$price) || die "failed to execute insert into parts query" . $dbh->errstr; - $dbh->commit || die $dbh->errstr; - $eth->finish || die "cannot finish " . $dbh->errstr; - $dbh->disconnect; - $retval = get_partid($myconfig, $form, $code); - } - - return($retval); -} diff --git a/accounting/ws_server_28.pl b/accounting/ws_server_28.pl deleted file mode 100644 index 93553fc36..000000000 --- a/accounting/ws_server_28.pl +++ /dev/null @@ -1,381 +0,0 @@ -#!/usr/bin/perl - -###################################################################### -# This module is compatible only with SQL-Ledger version 2.8.x. -# Copy it to your SQL-Ledger installation directory as ws_server.pl. -###################################################################### - -use Frontier::Responder; -use DBI; - -###################################################################### -# IMPORTANT - modify this to point to your SQL-Ledger installation! -###################################################################### -use lib qw (/var/www/sql-ledger); - -use SL::User; -use SL::Form; -use SL::CT; -use SL::HR; -use SL::IS; -use SL::IC; -use SL::AA; - -require "sql-ledger.conf"; - -my $add_customer = \&rpc_add_customer; -my $add_salesman = \&rpc_add_employee; -my $add_invoice = \&rpc_add_invoice; -my $customer_balance = \&rpc_customer_balance; - -# In case we are running under Windows, do not strip carriage returns -# from POSTed data, otherwise Frontier::Responder may fail. -binmode(STDIN); - -my $res = Frontier::Responder->new( methods => { - 'ezybiz.add_invoice' => $add_invoice, - 'ezybiz.add_salesman' => $add_salesman, - 'ezybiz.customer_balance' =>$customer_balance, - 'ezybiz.add_customer' => $add_customer -}, ); - -print $res->answer; - -sub rpc_customer_balance { - my ($post_hash) = @_; - if ($$post_hash{id} > 0 ) { - my $myconfig = new User "$memberfile", "$oemr_username"; - $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; - my $form = new Form; - $form->{title} = "AR Outstanding"; - $form->{outstanding} = "1"; - $form->{customer_id} = $$post_hash{id}; - $form->{sort} = "transdate" ; - $form->{l_due} = 1; - $form->{nextsub} = "transaction"; - $form->{vc} = "customer" ; - $form->{action} = 'Continue'; - - AA::transactions("",\%$myconfig, \%$form); - - my ($paid,$amount) = 0; - - # Exclude invoices that are not yet due (i.e. waiting for insurance). - # We no longer use the due date for this; instead ar.notes identifies - # insurances used, and ar.shipvia indicates which of those are done. - # If all insurances are done, it's due. - # - foreach my $resref (@{$$form{transactions}}) { - my $inspending = 0; - foreach my $tmp ('Ins1','Ins2','Ins3') { - ++$inspending if ($$resref{notes} =~ /$tmp/ && $$resref{shipvia} !~ /$tmp/); - } - if ($inspending == 0) { - $paid += $$resref{paid}; - $amount += $$resref{amount}; - } - } - - my $retval = $amount - $paid; - return($retval); - } -} - -sub rpc_add_customer -{ - use lib '/usr/lib/perl5/site_perl/5.8.5'; - - my ($post_hash) = @_; - - #take struct of data and map to post data to create the customer, return the id - my $myconfig = new User "$memberfile", "$oemr_username"; - $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; - my $form = new Form; - $form->{name} = ""; - $form->{db} = "customer"; - $form->{contact} = ""; - $form->{firstname} = $$post_hash{'firstname'}; - $form->{lastname} = $$post_hash{'lastname'}; - $form->{threshold} = "0"; - $form->{cashdiscount} = ""; - $form->{discountterms} = ""; - $form->{taxincluded} = "0"; - $form->{creditlimit} = "0"; - $form->{id} = $$post_hash{'foreign_id'}; - $form->{login} = ""; - $form->{employee_id} = "$oemr_username"; - $form->{pricegroup} = ""; - $form->{business} = ""; - $form->{language} = ""; - $form->{curr} = "USD"; - $form->{customernumber} = $$post_hash{'customernumber'}; - - @t = localtime(time); - $dd = $t[3]; - $mm = $t[4] + 1; - $yy = $t[5] + 1900; - - $form->{startdate} = "$mm-$dd-$yy"; - - # find the contact if it exists and add to form - my $trans_id = 0; - my $dbh = $form->dbconnect($myconfig); - my $query = qq|SELECT id FROM contact WHERE trans_id = ?|; - my $eth = $dbh->prepare($query) || die "Failed to prepare address query"; - $eth->execute($$post_hash{'foreign_id'}) || die "Failed to execute address query"; - ($trans_id) = $eth->fetchrow_array; - $eth->finish; - - $form->{contactid} = ""; - if ($trans_id) { - $form->{contactid} = $trans_id; - } - - $form->{phone} = substr($$post_hash{'phone1'}, 0, 20); - $form->{fax} = substr($$post_hash{'phone2'}, 0, 20); - $form->{mobile} = substr($$post_hash{'phone3'}, 0, 20); - $form->{email} = $$post_hash{'email'}; - $form->{typeofcontact} = "person"; - - # find the address if it exists and add to form - my $trans_id = 0; - my $dbh = $form->dbconnect($myconfig); - my $query = qq|SELECT id FROM address WHERE trans_id = ?|; - my $eth = $dbh->prepare($query) || die "Failed to prepare address query"; - $eth->execute($$post_hash{'foreign_id'}) || die "Failed to execute address query"; - ($trans_id) = $eth->fetchrow_array; - $eth->finish; - - $form->{addressid} = ""; - if ($trans_id) { - $form->{addressid} = $trans_id; - } - - $form->{address1} = substr($$post_hash{'address'}, 0, 32); - $form->{address2} = substr($$post_hash{'address'}, 32, 32); - $form->{city} = substr($$post_hash{'suburb'}, 0, 32); - if($$post_hash{'state'}){ - $form->{state} = substr($$post_hash{'state'}, 0, 32); - }else{ - $form->{state} = substr($$post_hash{'geo_zone_id'}, 0, 32); - } - $form->{zipcode} = substr($$post_hash{'postcode'}, 0, 10); - $form->{country} = ""; - - # This is if you want to use sql-ledger for more than just insurance billing - # and need to collect sales tax for your state on any items you sell directly - # to the patient. You need to define your sql-ledger tax account and your - # state in the sql-ledger.conf file. Additionally, you need to be sure you - # have *at least* set the state in your patient demographics to give this - # something to match to. - if ($oemr_sales_tax) { - if ( $oemr_state =~ m/^$$post_hash{'state'}/i || $oemr_geo_zone =~ m/^$$post_hash{'geo_zone_id'}/) { - $form->{taxaccounts} = "$oemr_sales_tax"; - $form->{"tax_$oemr_sales_tax"} = "1"; - } - } - - CT::save('', \%$myconfig, \%$form); - my $retVal = $form->{id}; - - return($retVal); -} - -sub rpc_add_employee -{ - my ($post_hash) = @_; - my $myconfig = new User "$memberfile", "$oemr_username"; - $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; - my $form = new Form; - $form->{id} = $$post_hash{'foreign_id'}; - $form->{name} = $$post_hash{'fname'} . " " . $$post_hash{'lname'}; - $form->{sales} = $$post_hash{'authorized'}; - @t = localtime(time); - $dd = $t[3]; - $mm = $t[4] + 1; - $yy = $t[5] + 1900; - - $form->{startdate} = "$mm-$dd-$yy"; - HR::save_employee("",\%$myconfig, \%$form); - my $retVal = $form->{id}; - return($retVal); -} - -sub rpc_add_invoice -{ - my ($post_hash) = @_; - - my $myconfig = new User "$memberfile", "$oemr_username"; - $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; - my $form = new Form; - $form->{id}; - $form->{employee} = "--" . $$post_hash{'salesman'}; - $form->{customer_id} = $$post_hash{'customerid'}; - $form->{invnumber} = $$post_hash{'invoicenumber'}; - $form->{amount} = $$post_hash{'total'}; - $form->{netamount} = $$post_hash{'total'}; - $form->{notes} = $$post_hash{'notes'}; - $form->{department} = ""; - $form->{currency} = "USD"; - $form->{defaultcurrency} = "USD"; - - # This is the AR account number, needed by IS::post_invoice. - $form->{AR} = $oemr_ar_acc; - - # This will use the posting date as the billing date - @t = localtime(time); - - # $dd = $t[3]; - # $mm = $t[4] + 1; - # $yy = $t[5] + 1900; - - $form->{transdate} = sprintf("%02u-%02u-%04u", $t[4] + 1, $t[3], $t[5] + 1900); - - # This overrides the above statement to use the date of service as the - # invoice date, which should be preferable for most practices. Comment - # out the following line if you really want the billing date instead. - # - $form->{transdate} = $$post_hash{'dosdate'}; - - # If there is insurance, set a future due date so we don't bother - # the patient for a while. - # - if ($$post_hash{'payer_id'}) { - @t = localtime(60 * 60 * 24 * $oemr_due_days + time); - $form->{duedate} = sprintf("%02u-%02u-%04u", $t[4] + 1, $t[3], $t[5] + 1900); - } else { - $form->{duedate} = $form->{transdate}; - } - - # Get out if the invoice already exists. - my $trans_id = 0; - my $dbh = $form->dbconnect($myconfig); - my $query = qq|SELECT id FROM ar WHERE invnumber = ?|; - my $eth = $dbh->prepare($query) || die "Failed to prepare ar query"; - $eth->execute($$post_hash{'invoicenumber'}) || die "Failed to execute ar query"; - ($trans_id) = $eth->fetchrow_array; - $eth->finish; - - if ($trans_id) { - print STDERR "Skipping invoice $trans_id = " . $$post_hash{'invoicenumber'} . "\n"; - $dbh->disconnect; - return 0; - } - - #loop through line items and add them to invoice - my $i = 1; - my $j = 1; #this is for copays should only be one but who knows -j - my $count = 0; - my $items = $$post_hash{'items'}; - - foreach my $line_item (@$items) - { - if ($$line_item{'itemtext'} =~ /COPAY/) { - $form->{"datepaid_$j"} = $form->{transdate}; # "$mm-$dd-$yy"; - # For copays we use a dummy procedure code because it may be applicable - # to multiple procedures during the visit. - $form->{"memo_$j"} = 'Co-pay'; - # Put the payment method and check number in the source field if they are - # present (i.e. from pos_checkout.php). - if ($$line_item{'itemtext'} =~ /^COPAY:([A-Z].*)$/) { - $form->{"source_$j"} = $1; - } else { - $form->{"source_$j"} = 'Co-pay'; - } - # $form->{"paid_$j"} = abs($$line_item{'price'}); - $form->{"paid_$j"} = 0 - $$line_item{'price'}; - $form->{"AR_paid_$j"} = "$oemr_cash_acc" . "--"; - $j++; - } - else{ - my $chart_id = 0; - my $query = qq|SELECT id FROM chart WHERE accno = ?|; - my $eth = $dbh->prepare($query) || die "Failed to prepare chart query"; - $eth->execute($$line_item{'glaccountid'}) || die "Failed to execute chart query"; - ($chart_id) = $eth->fetchrow_array; - $eth->finish; - - # Frederick says: - # The reason for this was that as a positive value, the AR transaction - # was being added as a credit note and giving credit to the patient. By - # making it negative, it is created as a sales transaction, making it - # balance due. - $$line_item{'qty'} = 0 - $$line_item{'qty'} if ($$line_item{'qty'} > 0); - - $form->{"qty_$i"} = $$line_item{'qty'}; - $form->{"discount_$i"} = 0; - $form->{"sellprice_$i"} = $$line_item{'price'}; - - unless ($oemr_sales_tax) { - # These were the original settings for sales tax. They don't really - # matter since the MS item shouldn't have sales tax turned on anyway. - $form->{taxincluded} = 1; - $form->{"taxaccounts_$i"} = 0; - } - - $form->{"income_accno_$i"} = $$line_item{'glaccountid'}; - $form->{"income_accno_id_$i"} = $chart_id; - - $form->{"id_$i"} = add_goodsandservices(\%$myconfig, \%$form, $oemr_services_partnumber, - 'Medical Services', '0.0'); - - $form->{"description_$i"} = $$line_item{'itemtext'}; - $form->{"unit_$i"} = ''; - $form->{"serialnumber_$i"} = $$line_item{'maincode'}; - - # Save the insurance company ID as the SL project ID. This gives us a way - # to associate each invoice item with its insurance payer. The clinic will - # probably want to write some reporting software taking advantage of this. - # - $form->{"projectnumber_$i"} = "--" . $$post_hash{'payer_id'} - if ($$post_hash{'payer_id'}); - $i++; - } - } - - $dbh->disconnect; - - $form->{paidaccounts} = $j - 1; - $form->{rowcount} = $i - 1; - IS::post_invoice("", \%$myconfig, \%$form); - my $retVal = $form->{id}; - return($retVal); -} - -sub get_partid -{ - my ($myconfig, $form, $number) = @_; - my $retval = 0; - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my $query = qq|SELECT id FROM parts WHERE partnumber = ?|; - my $eth = $dbh->prepare($query) || die "Failed to create select id from parts query"; - $eth->execute($number) || die "Failed to execute select id from parts query"; - ($retval) = $eth->fetchrow_array; - $eth->finish; - $dbh->disconnect; - return($retval); -} - -sub add_goodsandservices -{ - my ($myconfig, $form, $code, $desc, $price) = @_; - my $retval = 0; - $retval = get_partid($myconfig, $form, $code); - - if($retval == 0) - { - # connect to database, turn off autocommit - my $dbh = $form->dbconnect_noauto($myconfig); - my $query = qq|insert into parts (partnumber,description,listprice,sellprice) values(?,?,?,?)|; - my $eth = $dbh->prepare($query) || die "failed to create insert into parts query" . $dbh->errstr; - $eth->execute($code,$desc,$price,$price) || die "failed to execute insert into parts query" . $dbh->errstr; - $dbh->commit || die $dbh->errstr; - $eth->finish || die "cannot finish " . $dbh->errstr; - $dbh->disconnect; - $retval = get_partid($myconfig, $form, $code); - } - - return($retval); -} diff --git a/interface/billing/era_payments.php b/interface/billing/era_payments.php index 0e8c12d5b..a670e76ee 100644 --- a/interface/billing/era_payments.php +++ b/interface/billing/era_payments.php @@ -29,7 +29,6 @@ //=============================================================================== require_once("../globals.php"); require_once("$srcdir/patient.inc"); -require_once("$srcdir/sql-ledger.inc"); require_once("$srcdir/invoice_summary.inc.php"); require_once($GLOBALS['OE_SITE_DIR'] . "/statement.inc.php"); require_once("$srcdir/parse_era.inc.php"); @@ -43,18 +42,14 @@ $eraname = ''; $eracount = 0; $Processed=0; function era_callback(&$out) { - global $where, $eracount, $eraname, $INTEGRATED_AR; + global $where, $eracount, $eraname; ++$eracount; $eraname = $out['gs_date'] . '_' . ltrim($out['isa_control_number'], '0') . '_' . ltrim($out['payer_id'], '0'); list($pid, $encounter, $invnumber) = slInvoiceNumber($out); if ($pid && $encounter) { if ($where) $where .= ' OR '; - if ($INTEGRATED_AR) { $where .= "( f.pid = '$pid' AND f.encounter = '$encounter' )"; - } else { - $where .= "invnumber = '$invnumber'"; - } } } //=============================================================================== diff --git a/interface/billing/indigent_patients_report.php b/interface/billing/indigent_patients_report.php index 911463c7c..1900773b7 100644 --- a/interface/billing/indigent_patients_report.php +++ b/interface/billing/indigent_patients_report.php @@ -12,7 +12,6 @@ require_once("../globals.php"); require_once("$srcdir/patient.inc"); -require_once("$srcdir/sql-ledger.inc"); require_once("$srcdir/formatting.inc.php"); $alertmsg = ''; @@ -25,9 +24,6 @@ function bucks($amount) { $form_start_date = fixDate($_POST['form_start_date'], date("Y-01-01")); $form_end_date = fixDate($_POST['form_end_date'], date("Y-m-d")); -$INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2; - -if (!$INTEGRATED_AR) SLConnect(); ?> @@ -173,7 +169,7 @@ if (!$INTEGRATED_AR) SLConnect(); diff --git a/interface/billing/sl_eob_invoice.php b/interface/billing/sl_eob_invoice.php index 31af83863..e96432cb7 100644 --- a/interface/billing/sl_eob_invoice.php +++ b/interface/billing/sl_eob_invoice.php @@ -20,9 +20,12 @@ * @package OpenEMR * @author Rod Roark * @author Roberto Vasquez + * @author Terry Hill * @link http://www.open-emr.org */ + + require_once("../globals.php"); require_once("$srcdir/log.inc"); require_once("$srcdir/patient.inc"); @@ -34,10 +37,9 @@ $debug = 0; // set to 1 for debugging mode - $INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2; // If we permit deletion of transactions. Might change this later. - $ALLOW_DELETE = $INTEGRATED_AR; + $ALLOW_DELETE = true; $info_msg = ""; @@ -80,22 +82,6 @@ // An insurance radio button is selected. function setins(istr) { - - var f = document.forms[0]; - for (var i = 0; i < f.elements.length; ++i) { - var ename = f.elements[i].name; - if (ename.indexOf('[src]') < 0) continue; - var evalue = f.elements[i].value; - var tmp = evalue.substring(0, 4).toLowerCase(); - if (tmp >= 'ins1' && tmp <= 'ins3') - evalue = evalue.substring(4); - else if (evalue.substring(0, 2).toLowerCase() == 'pt') - evalue = evalue.substring(2); - while (evalue.substring(0, 1) == '/') - evalue = evalue.substring(1); - f.elements[i].value = istr + '/' + evalue; - } - return true; } @@ -127,44 +113,6 @@ function validate(f) { var pfx = ename.substring(0, pfxlen); var code = pfx.substring(pfx.indexOf('[')+1, pfxlen-1); if (f[pfx+'[pay]'].value || f[pfx+'[adj]'].value) { - - var srcobj = f[pfx+'[src]']; - while (srcobj.value.length) { - var tmp = srcobj.value.substring(srcobj.value.length - 1); - if (tmp > ' ' && tmp != '/') break; - srcobj.value = srcobj.value.substring(0, srcobj.value.length - 1); - } - var svalue = srcobj.value; - if (! svalue) { - alert('' + code); - return false; - } else { - var tmp = svalue.substring(0, 4).toLowerCase(); - if (tmp >= 'ins1' && tmp <= 'ins3') { - svalue = svalue.substring(4); - } else if (svalue.substring(0, 2).toLowerCase() == 'pt') { - svalue = svalue.substring(2); - } else { - alert('' + code); - return false; - } - if (svalue) { - if (svalue.substring(0, 1) != '/') { - alert('' + code); - return false; - } - if (false) { // Please keep this, Oakland Clinic wants it. -- Rod - tmp = svalue.substring(1, 3).toLowerCase(); - if (tmp != 'nm' && tmp != 'ci' && tmp != 'cp' && tmp != 'ne' && - tmp != 'it' && tmp != 'pf' && tmp != 'pp' && tmp != 'ok') - { - alert('' + tmp + '' + code); - return false; - } - } // End of OC code - } - } - if (! f[pfx+'[date]'].value) { alert('' + code); return false; @@ -246,8 +194,7 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode) $trans_id = 0 + $_GET['id']; if (! $trans_id) die(xl("You cannot access this page directly.")); - if ($INTEGRATED_AR) { - // In the Integrated A/R case, $trans_id matches form_encounter.id. + // A/R case, $trans_id matches form_encounter.id. $ferow = sqlQuery("SELECT e.*, p.fname, p.mname, p.lname " . "FROM form_encounter AS e, patient_data AS p WHERE " . "e.id = '$trans_id' AND p.pid = e.pid"); @@ -260,10 +207,6 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode) $form_check_date = fixDate($_POST['form_check_date'], date('Y-m-d')); $form_deposit_date = fixDate($_POST['form_deposit_date'], $form_check_date); $form_pay_total = 0 + $_POST['form_pay_total']; - } - else { - slInitialize(); - } $payer_type = 0; if (preg_match('/^Ins(\d)/i', $_POST['form_insurance'], $matches)) { @@ -276,7 +219,6 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode) echo xl("This module is in test mode. The database will not be changed.",'','

',"

\n"); } - if ($INTEGRATED_AR) { $session_id = arGetSession($form_payer_id, $form_reference, $form_check_date, $form_deposit_date, $form_pay_total); // The sl_eob_search page needs its invoice links modified to invoke @@ -293,14 +235,9 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode) "encounter = '$encounter_id' AND sequence_no = '$arseq'"); } } - } $paytotal = 0; foreach ($_POST['form_line'] as $code => $cdata) { - if (!$INTEGRATED_AR) { - $thissrc = trim($cdata['src']); - $thisdate = trim($cdata['date']); - } $thispay = trim($cdata['pay']); $thisadj = trim($cdata['adj']); $thisins = trim($cdata['ins']); @@ -336,12 +273,8 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode) if (! $thisins) $thisins = 0; if ($thispay) { - if ($INTEGRATED_AR) { arPostPayment($patient_id, $encounter_id, $session_id, $thispay, $code, $payer_type, '', $debug, '', $thiscodetype); - } else { - slPostPayment($trans_id, $thispay, $thisdate, $thissrc, $code, $thisins, $debug); - } $paytotal += $thispay; } @@ -373,53 +306,23 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode) if (strpos(strtolower($reason), 'ins') !== false) $reason .= ' ' . $_POST['form_insurance']; } - if ($INTEGRATED_AR) { arPostAdjustment($patient_id, $encounter_id, $session_id, $thisadj, $code, $payer_type, $reason, $debug, '', $thiscodetype); - } else { - slPostAdjustment($trans_id, $thisadj, $thisdate, $thissrc, $code, $thisins, $reason, $debug); - } } } // Maintain which insurances are marked as finished. - if ($INTEGRATED_AR) { $form_done = 0 + $_POST['form_done']; $form_stmt_count = 0 + $_POST['form_stmt_count']; sqlStatement("UPDATE form_encounter " . "SET last_level_closed = $form_done, " . "stmt_count = $form_stmt_count WHERE " . "pid = '$patient_id' AND encounter = '$encounter_id'"); - } - else { - $form_duedate = fixDate($_POST['form_duedate']); - $form_notes = trim($_POST['form_notes']); - // We use the "Ship Via" field of the invoice to hold these. - $form_eobs = ""; - foreach (array('Ins1', 'Ins2', 'Ins3') as $value) { - if ($_POST["form_done_$value"]) { - if ($form_eobs) $form_eobs .= ","; else $form_eobs = "Done: "; - $form_eobs .= $value; - } - } - $query = "UPDATE ar SET duedate = '$form_duedate', notes = '$form_notes', " . - "shipvia = '$form_eobs' WHERE id = $trans_id"; - if ($debug) { - echo $query . "
\n"; - } else { - SLQuery($query); - if ($sl_err) die($sl_err); - } - } if ($_POST['form_secondary']) { - if ($INTEGRATED_AR) { arSetupSecondary($patient_id, $encounter_id, $debug); - } else { - slSetupSecondary($trans_id, $debug); } - } echo "\n"; - if (!$INTEGRATED_AR) SLClose(); exit(); } - if ($INTEGRATED_AR) { // Get invoice charge details. $codes = ar_get_invoice_summary($patient_id, $encounter_id, true); - } - else { - // Get invoice data into $arrow. - $arres = SLQuery("select ar.*, customer.name, employee.name as doctor " . - "from ar, customer, employee where ar.id = $trans_id and " . - "customer.id = ar.customer_id and employee.id = ar.employee_id"); - if ($sl_err) die($sl_err); - $arrow = SLGetRow($arres, 0); - if (! $arrow) die(xl("There is no match for invoice id = ") . $trans_id); - // - // Determine the date of service. An 8-digit encounter number is - // presumed to be a date of service imported during conversion. - // Otherwise look it up in the form_encounter table. - // - $svcdate = ""; - list($patient_id, $encounter) = explode(".", $arrow['invnumber']); - if (strlen($encounter) == 8) { - $svcdate = substr($encounter, 0, 4) . "-" . substr($encounter, 4, 2) . - "-" . substr($encounter, 6, 2); - } - else if ($encounter) { - $tmp = sqlQuery("SELECT date FROM form_encounter WHERE " . - "encounter = $encounter"); - $svcdate = substr($tmp['date'], 0, 10); - } - - // Get invoice charge details. - $codes = get_invoice_summary($trans_id, true); - } $pdrow = sqlQuery("select billing_note " . "from patient_data where pid = '$patient_id' limit 1"); @@ -484,17 +356,11 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode) "; } } - } - else { - echo " \n"; - } ?> \n"; echo xl('Statements Sent:'); echo "\n"; @@ -519,7 +378,6 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode) echo "\n"; echo "\n"; - } ?> @@ -528,7 +386,6 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode) @@ -549,12 +402,7 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode) @@ -573,37 +421,21 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode) 'None', 1 => 'Ins1', 2 => 'Ins2', 3 => 'Ins3') as $key => $value) { if ($key && !arGetPayerID($patient_id, $svcdate, $key)) continue; $checked = ($last_level_closed == $key) ? " checked" : ""; echo " $value \n"; } - } - else { - // The information is stored in the 'shipvia' field of the invoice. - $insgot = strtolower($arrow['notes']); - $insdone = strtolower($arrow['shipvia']); - foreach (array('Ins1', 'Ins2', 'Ins3') as $value) { - $lcvalue = strtolower($value); - $checked = (strpos($insdone, $lcvalue) === false) ? "" : " checked"; - if (strpos($insgot, $lcvalue) !== false) { - echo " $value \n"; - } - } - } ?> \n"; echo xl('Check/EOB No.:'); echo "\n"; echo "\n"; echo "\n"; echo "\n"; - } ?> @@ -613,12 +445,7 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode) @@ -639,28 +466,18 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode) \n"; echo xl('Check/EOB Date:'); echo "\n"; echo "\n"; echo "\n"; echo "\n"; - } ?> - - - - ' - title=''> - @@ -670,7 +487,6 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode) ' onclick='window.close()'> \n"; echo xl('Deposit Date:'); echo "\n"; @@ -682,7 +498,6 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode) echo "\n"; echo "\n"; echo "\n"; - } ?> @@ -825,19 +640,10 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode) - - - - - - - @@ -886,7 +692,6 @@ while ($orow = sqlFetchArray($ores)) { @@ -897,7 +702,6 @@ while ($orow = sqlFetchArray($ores)) { var f2 = document.forms[0]; if (f1.form_source) { $cdata) { - echo " f2['form_line[$code][src]'].value = f1.form_source.value;\n"; - echo " f2['form_line[$code][date]'].value = f1.form_paydate.value;\n"; - } - } ?> } setins("Ins1"); diff --git a/interface/billing/sl_eob_process.php b/interface/billing/sl_eob_process.php index bd4ac19eb..00be07bae 100644 --- a/interface/billing/sl_eob_process.php +++ b/interface/billing/sl_eob_process.php @@ -30,7 +30,6 @@ require_once("$srcdir/billing.inc"); $last_code = ''; $invoice_total = 0.00; $InsertionId;//last inserted ID of - $INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2; ///////////////////////// Assorted Functions ///////////////////////// @@ -160,7 +159,7 @@ require_once("$srcdir/billing.inc"); } function era_callback(&$out) { global $encount, $debug, $claim_status_codes, $adjustment_reasons, $remark_codes; - global $invoice_total, $last_code, $paydate, $INTEGRATED_AR; + global $invoice_total, $last_code, $paydate; global $InsertionId;//last inserted ID of @@ -187,7 +186,6 @@ require_once("$srcdir/billing.inc"); $codes = array(); if ($pid && $encounter) { // Get invoice data into $arrow or $ferow. - if ($INTEGRATED_AR) { $ferow = sqlQuery("SELECT e.*, p.fname, p.mname, p.lname " . "FROM form_encounter AS e, patient_data AS p WHERE " . "e.pid = '$pid' AND e.encounter = '$encounter' AND ". @@ -200,21 +198,6 @@ require_once("$srcdir/billing.inc"); $codes = ar_get_invoice_summary($pid, $encounter, true); // $svcdate = substr($ferow['date'], 0, 10); } - } // end internal a/r - else { - $arres = SLQuery("SELECT ar.id, ar.notes, ar.shipvia, customer.name " . - "FROM ar, customer WHERE ar.invnumber = '$invnumber' AND " . - "customer.id = ar.customer_id"); - if ($sl_err) die($sl_err); - $arrow = SLGetRow($arres, 0); - if ($arrow) { - $inverror = false; - $codes = get_invoice_summary($arrow['id'], true); - } else { // oops, no such invoice - $pid = $encounter = 0; - $invnumber = $out['our_claim_id']; - } - } // end not internal a/r } // Show the claim status. @@ -277,24 +260,12 @@ require_once("$srcdir/billing.inc"); $check_date = $paydate ? $paydate : parse_date($out['check_date']); $production_date = $paydate ? $paydate : parse_date($out['production_date']); - if ($INTEGRATED_AR) { $insurance_id = arGetPayerID($pid, $service_date, substr($inslabel, 3)); if (empty($ferow['lname'])) { $patient_name = $out['patient_fname'] . ' ' . $out['patient_lname']; } else { $patient_name = $ferow['fname'] . ' ' . $ferow['lname']; } - } else { - $insurance_id = 0; - foreach ($codes as $cdata) { - if ($cdata['ins']) { - $insurance_id = $cdata['ins']; - break; - } - } - $patient_name = $arrow['name'] ? $arrow['name'] : - ($out['patient_fname'] . ' ' . $out['patient_lname']); - } $error = $inverror; @@ -344,13 +315,8 @@ require_once("$srcdir/billing.inc"); // was inserted, or in red if we are in error mode). $description = "CPT4:$codekey Added by $inslabel $production_date"; if (!$error && !$debug) { - if ($INTEGRATED_AR) { arPostCharge($pid, $encounter, 0, $svc['chg'], 1, $service_date, $codekey, $description, $debug,'',$codetype); - } else { - slPostCharge($arrow['id'], $svc['chg'], 1, $service_date, $codekey, - $insurance_id, $description, $debug); - } $invoice_total += $svc['chg']; } $class = $error ? 'errdetail' : 'newdetail'; @@ -393,13 +359,8 @@ require_once("$srcdir/billing.inc"); // i.e. a payment reversal. if ($svc['paid']) { if (!$error && !$debug) { - if ($INTEGRATED_AR) { arPostPayment($pid, $encounter,$InsertionId[$out['check_number']], $svc['paid'],//$InsertionId[$out['check_number']] gives the session id $codekey, substr($inslabel,3), $out['check_number'], $debug,'',$codetype); - } else { - slPostPayment($arrow['id'], $svc['paid'], $check_date, - "$inslabel/" . $out['check_number'], $codekey, $insurance_id, $debug); - } $invoice_total -= $svc['paid']; } $description = "$inslabel/" . $out['check_number'] . ' payment'; @@ -440,14 +401,8 @@ require_once("$srcdir/billing.inc"); $reason .= sprintf("%.2f", $adj['amount']); // Post a zero-dollar adjustment just to save it as a comment. if (!$error && !$debug) { - if ($INTEGRATED_AR) { arPostAdjustment($pid, $encounter, $InsertionId[$out['check_number']], 0, $codekey,//$InsertionId[$out['check_number']] gives the session id substr($inslabel,3), $reason, $debug, '', $codetype); - } else { - slPostAdjustment($arrow['id'], 0, $production_date, - $out['check_number'], $codekey, $insurance_id, - $reason, $debug); - } } writeMessageLine($bgcolor, $class, $description . ' ' . sprintf("%.2f", $adj['amount'])); @@ -455,15 +410,9 @@ require_once("$srcdir/billing.inc"); // Other group codes for primary insurance are real adjustments. else { if (!$error && !$debug) { - if ($INTEGRATED_AR) { arPostAdjustment($pid, $encounter, $InsertionId[$out['check_number']], $adj['amount'],//$InsertionId[$out['check_number']] gives the session id $codekey, substr($inslabel,3), "Adjust code " . $adj['reason_code'], $debug, '', $codetype); - } else { - slPostAdjustment($arrow['id'], $adj['amount'], $production_date, - $out['check_number'], $codekey, $insurance_id, - "$inslabel adjust code " . $adj['reason_code'], $debug); - } $invoice_total -= $adj['amount']; } writeDetailLine($bgcolor, $class, $patient_name, $invnumber, @@ -490,7 +439,6 @@ require_once("$srcdir/billing.inc"); // Cleanup: If all is well, mark Ins done and check for secondary billing. if (!$error && !$debug && $insurance_done) { - if ($INTEGRATED_AR) { $level_done = 0 + substr($inslabel, 3); if($out['crossover']==1) @@ -516,24 +464,6 @@ require_once("$srcdir/billing.inc"); 'This claim is now re-queued for secondary paper billing'); } } - } else { - $shipvia = 'Done: Ins1'; - if ($inslabel != 'Ins1') $shipvia .= ',Ins2'; - if ($inslabel == 'Ins3') $shipvia .= ',Ins3'; - $query = "UPDATE ar SET shipvia = '$shipvia' WHERE id = " . $arrow['id']; - SLQuery($query); - if ($sl_err) die($sl_err); - // Check for secondary insurance. - $insgot = strtolower($arrow['notes']); - if ($primary && strpos($insgot, 'ins2') !== false) { - slSetupSecondary($arrow['id'], $debug); - if($out['crossover']<>1) - { - writeMessageLine($bgcolor, 'infdetail', - 'This claim is now re-queued for secondary paper billing'); - } - } - } } } } @@ -560,7 +490,6 @@ require_once("$srcdir/billing.inc"); if (!$fhreport) die(xl("Cannot create") . " '$fnreport'"); } - if (!$INTEGRATED_AR) slInitialize(); ?> @@ -645,7 +574,6 @@ require_once("$srcdir/billing.inc"); echo ""; } - if (!$INTEGRATED_AR) slTerminate(); ?> diff --git a/interface/billing/sl_eob_search.php b/interface/billing/sl_eob_search.php index e6b998875..7b921d9de 100644 --- a/interface/billing/sl_eob_search.php +++ b/interface/billing/sl_eob_search.php @@ -26,7 +26,6 @@ require_once("../globals.php"); require_once("$srcdir/patient.inc"); -require_once("$srcdir/sql-ledger.inc"); require_once("$srcdir/invoice_summary.inc.php"); require_once($GLOBALS['OE_SITE_DIR'] . "/statement.inc.php"); require_once("$srcdir/parse_era.inc.php"); @@ -36,7 +35,6 @@ require_once("$srcdir/classes/class.ezpdf.php");//for the purpose of pdf creatio $DEBUG = 0; // set to 0 for production, 1 to test -$INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2; $alertmsg = ''; $where = ''; @@ -46,7 +44,7 @@ $eracount = 0; // This is called back by parse_era() if we are processing X12 835's. // function era_callback(&$out) { - global $where, $eracount, $eraname, $INTEGRATED_AR; + global $where, $eracount, $eraname; // print_r($out); // debugging ++$eracount; // $eraname = $out['isa_control_number']; @@ -56,11 +54,7 @@ function era_callback(&$out) { if ($pid && $encounter) { if ($where) $where .= ' OR '; - if ($INTEGRATED_AR) { $where .= "( f.pid = '$pid' AND f.encounter = '$encounter' )"; - } else { - $where .= "invnumber = '$invnumber'"; - } } } @@ -138,7 +132,6 @@ function upload_file_to_client_pdf($file_to_send) { $today = date("Y-m-d"); -if ($INTEGRATED_AR) { // Print or download statements if requested. // @@ -271,171 +264,6 @@ if ($INTEGRATED_AR) { } // end not debug } // end not form_download } // end statements requested -} // end $INTEGRATED_AR -else { - SLConnect(); - - // This will be true starting with SQL-Ledger 2.8.x: - $got_address_table = SLQueryValue("SELECT count(*) FROM pg_tables WHERE " . - "schemaname = 'public' AND tablename = 'address'"); - - // Print or download statements if requested. - // - if (($_POST['form_print'] || $_POST['form_download'] || $_POST['form_pdf']) && $_POST['form_cb']) { - - $fhprint = fopen($STMT_TEMP_FILE, 'w'); - - $where = ""; - foreach ($_POST['form_cb'] as $key => $value) $where .= " OR ar.id = $key"; - $where = substr($where, 4); - - // Sort by patient so that multiple invoices can be - // represented on a single statement. - if ($got_address_table) { - $res = SLQuery("SELECT ar.*, customer.name, " . - "address.address1, address.address2, " . - "address.city, address.state, address.zipcode, " . - "substring(trim(both from customer.name) from '% #\"%#\"' for '#') AS fname, " . - "substring(trim(both from customer.name) from '#\"%#\" %' for '#') AS lname " . - "FROM ar, customer, address WHERE ( $where ) AND " . - "customer.id = ar.customer_id AND " . - "address.trans_id = ar.customer_id " . - "ORDER BY lname, fname, ar.customer_id, ar.transdate"); - } - else { - $res = SLQuery("SELECT ar.*, customer.name, " . - "customer.address1, customer.address2, " . - "customer.city, customer.state, customer.zipcode, " . - "substring(trim(both from customer.name) from '% #\"%#\"' for '#') AS lname, " . - "substring(trim(both from customer.name) from '#\"%#\" %' for '#') AS fname " . - "FROM ar, customer WHERE ( $where ) AND " . - "customer.id = ar.customer_id " . - "ORDER BY lname, fname, ar.customer_id, ar.transdate"); - } - if ($sl_err) die($sl_err); - - $stmt = array(); - $stmt_count = 0; - - for ($irow = 0; $irow < SLRowCount($res); ++$irow) { - $row = SLGetRow($res, $irow); - - // Determine the date of service. An 8-digit encounter number is - // presumed to be a date of service imported during conversion. - // Otherwise look it up in the form_encounter table. - // - $svcdate = ""; - list($pid, $encounter) = explode(".", $row['invnumber']); - if (strlen($encounter) == 8) { - $svcdate = substr($encounter, 0, 4) . "-" . substr($encounter, 4, 2) . - "-" . substr($encounter, 6, 2); - } else if ($encounter) { - $tmp = sqlQuery("SELECT date FROM form_encounter WHERE " . - "encounter = $encounter"); - $svcdate = substr($tmp['date'], 0, 10); - } - - // How many times have we dunned them for this invoice? - $intnotes = trim($row['intnotes']); - $duncount = substr_count(strtolower($intnotes), "statement sent"); - - // If this is a new patient then print the pending statement - // and start a new one. This is an associative array: - // - // cid = SQL-Ledger customer ID - // pid = OpenEMR patient ID - // patient = patient name - // amount = total amount due - // adjust = adjustments (already applied to amount) - // duedate = due date of the oldest included invoice - // age = number of days from duedate to today - // to = array of addressee name/address lines - // lines = array of: - // dos = date of service "yyyy-mm-dd" - // desc = description - // amount = charge less adjustments - // paid = amount paid - // notice = 1 for first notice, 2 for second, etc. - // detail = array of details, see invoice_summary.inc.php - // - if ($stmt['cid'] != $row['customer_id']) { - if (!empty($stmt)) ++$stmt_count; - fwrite($fhprint, create_statement($stmt)); - $stmt['cid'] = $row['customer_id']; - $stmt['pid'] = $pid; - - if ($got_address_table) { - $stmt['patient'] = $row['fname'] . ' ' . $row['lname']; - $stmt['to'] = array($row['fname'] . ' ' . $row['lname']); - } else { - $stmt['patient'] = $row['name']; - $stmt['to'] = array($row['name']); - } - - if ($row['address1']) $stmt['to'][] = $row['address1']; - if ($row['address2']) $stmt['to'][] = $row['address2']; - $stmt['to'][] = $row['city'] . ", " . $row['state'] . " " . $row['zipcode']; - $stmt['lines'] = array(); - $stmt['amount'] = '0.00'; - $stmt['today'] = $today; - $stmt['duedate'] = $row['duedate']; - } else { - // Report the oldest due date. - if ($row['duedate'] < $stmt['duedate']) { - $stmt['duedate'] = $row['duedate']; - } - } - - $stmt['age'] = round((strtotime($today) - strtotime($stmt['duedate'])) / - (24 * 60 * 60)); - - $invlines = get_invoice_summary($row['id'], true); // true added by Rod 2006-06-09 - foreach ($invlines as $key => $value) { - $line = array(); - $line['dos'] = $svcdate; - $line['desc'] = ($key == 'CO-PAY') ? "Patient Payment" : "Procedure $key"; - $line['amount'] = sprintf("%.2f", $value['chg']); - $line['adjust'] = sprintf("%.2f", $value['adj']); - $line['paid'] = sprintf("%.2f", $value['chg'] - $value['bal']); - $line['notice'] = $duncount + 1; - $line['detail'] = $value['dtl']; // Added by Rod 2006-06-09 - $stmt['lines'][] = $line; - $stmt['amount'] = sprintf("%.2f", $stmt['amount'] + $value['bal']); - } - - // Record something in ar.intnotes about this statement run. - if ($intnotes) $intnotes .= "\n"; - $intnotes = addslashes($intnotes . "Statement sent $today"); - if (! $DEBUG && ! $_POST['form_without']) { - SLQuery("UPDATE ar SET intnotes = '$intnotes' WHERE id = " . $row['id']); - if ($sl_err) die($sl_err); - } - } // end for - - if (!empty($stmt)) ++$stmt_count; - fwrite($fhprint, create_statement($stmt)); - fclose($fhprint); - sleep(1); - - // Download or print the file, as selected - if ($_POST['form_download']) { - upload_file_to_client($STMT_TEMP_FILE); - } elseif ($_POST['form_pdf']) { - upload_file_to_client_pdf($STMT_TEMP_FILE); - } else { // Must be print! - if ($DEBUG) { - $alertmsg = xl("Printing skipped; see test output in") .' '. $STMT_TEMP_FILE; - } else { - exec("$STMT_PRINT_CMD $STMT_TEMP_FILE"); - if ($_POST['form_without']) { - $alertmsg = xl('Now printing') .' '. $stmt_count .' '. xl('statements; invoices will not be updated.'); - } else { - $alertmsg = xl('Now printing') .' '. $stmt_count .' '. xl('statements and updating invoices.'); - } - } // end not debug - } // end if form_download - } // end statements requested -} // end not $INTEGRATED_AR ?> @@ -475,7 +303,6 @@ function npopup(pid) { \n"; echo " " . xl('Payer') . ":\n"; @@ -491,7 +318,6 @@ if ($INTEGRATED_AR) { } echo " \n"; echo " \n"; -} ?> @@ -510,7 +336,6 @@ if ($INTEGRATED_AR) { title=''> - @@ -519,7 +344,6 @@ if ($INTEGRATED_AR) { onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title=''> - @@ -642,7 +466,6 @@ if ($_POST['form_search'] || $_POST['form_print']) { rename($tmp_name, $erafullname); } // End 835 upload - if ($INTEGRATED_AR) { if ($eracount) { // Note that parse_era() modified $eracount and $where. if (! $where) $where = '1 = 2'; @@ -723,112 +546,6 @@ if ($_POST['form_search'] || $_POST['form_print']) { $alertmsg .= "Of $eracount remittances, there are $num_invoices " . "matching encounters in OpenEMR. "; } - } // end $INTEGRATED_AR - else { - if ($eracount) { - // Note that parse_era() modified $eracount and $where. - if (! $where) $where = '1 = 2'; - } - else { - if ($form_name) { - if ($where) $where .= " AND "; - // Allow the last name to be followed by a comma and some part of a first name. - if (preg_match('/^(.*\S)\s*,\s*(.*)/', $form_name, $matches)) { - $where .= "customer.name ILIKE '" . $matches[2] . '% ' . $matches[1] . "%'"; - // Allow a filter like "A-C" on the first character of the last name. - } else if (preg_match('/^(\S)\s*-\s*(\S)$/', $form_name, $matches)) { - $tmp = '1 = 2'; - while (ord($matches[1]) <= ord($matches[2])) { - // $tmp .= " OR customer.name ILIKE '% " . $matches[1] . "%'"; - // Fixing the above which was also matching on middle names: - $tmp .= " OR customer.name ~* ' " . $matches[1] . "[A-Z]*$'"; - $matches[1] = chr(ord($matches[1]) + 1); - } - $where .= "( $tmp ) "; - } else { - $where .= "customer.name ILIKE '%$form_name%'"; - } - } - if ($form_pid && $form_encounter) { - if ($where) $where .= " AND "; - $where .= "ar.invnumber = '$form_pid.$form_encounter'"; - } - else if ($form_pid) { - if ($where) $where .= " AND "; - $where .= "ar.invnumber LIKE '$form_pid.%'"; - } - else if ($form_encounter) { - if ($where) $where .= " AND "; - $where .= "ar.invnumber like '%.$form_encounter'"; - } - - if ($form_date) { - if ($where) $where .= " AND "; - $date1 = substr($form_date, 0, 4) . substr($form_date, 5, 2) . - substr($form_date, 8, 2); - if ($form_to_date) { - $date2 = substr($form_to_date, 0, 4) . substr($form_to_date, 5, 2) . - substr($form_to_date, 8, 2); - $where .= "((CAST (substring(ar.invnumber from position('.' in ar.invnumber) + 1 for 8) AS integer) " . - "BETWEEN '$date1' AND '$date2')"; - $tmp = "date >= '$form_date' AND date <= '$form_to_date'"; - } - else { - // This catches old converted invoices where we have no encounters: - $where .= "(ar.invnumber LIKE '%.$date1'"; - $tmp = "date = '$form_date'"; - } - // Pick out the encounters from MySQL with the desired DOS: - $rez = sqlStatement("SELECT pid, encounter FROM form_encounter WHERE $tmp"); - while ($row = sqlFetchArray($rez)) { - $where .= " OR ar.invnumber = '" . $row['pid'] . "." . $row['encounter'] . "'"; - } - $where .= ")"; - } - - if (! $where) { - if ($_POST['form_category'] == 'All') { - die(xl("At least one search parameter is required if you select All.")); - } else { - $where = "1 = 1"; - } - } - } - - $query = "SELECT ar.id, ar.invnumber, ar.duedate, ar.amount, ar.paid, " . - "ar.intnotes, ar.notes, ar.shipvia, customer.name, customer.id AS custid, "; - if ($got_address_table) $query .= - "substring(trim(both from customer.name) from '#\"%#\" %' for '#') AS lname, " . - "substring(trim(both from customer.name) from '% #\"%#\"' for '#') AS fname, "; - else $query .= - "substring(trim(both from customer.name) from '% #\"%#\"' for '#') AS lname, " . - "substring(trim(both from customer.name) from '#\"%#\" %' for '#') AS fname, "; - $query .= - "(SELECT SUM(invoice.sellprice * invoice.qty) FROM invoice WHERE " . - "invoice.trans_id = ar.id AND invoice.sellprice > 0) AS charges, " . - "(SELECT SUM(invoice.sellprice * invoice.qty) FROM invoice WHERE " . - "invoice.trans_id = ar.id AND invoice.sellprice < 0) AS adjustments " . - "FROM ar, customer WHERE ( $where ) AND customer.id = ar.customer_id "; - if ($_POST['form_category'] != 'All' && !$eracount) { - $query .= "AND ar.amount != ar.paid "; - // if ($_POST['form_category'] == 'Due') { - // $query .= "AND ar.duedate <= CURRENT_DATE "; - // } - } - $query .= "ORDER BY lname, fname, ar.invnumber"; - - // echo "\n"; // debugging - - $t_res = SLQuery($query); - if ($sl_err) die($sl_err); - - $num_invoices = SLRowCount($t_res); - if ($eracount && $num_invoices != $eracount) { - $alertmsg .= "Of $eracount remittances, there are $num_invoices " . - "matching claims in OpenEMR. "; - } - - } // end not $INTEGRATED_AR ?> @@ -844,7 +561,7 @@ if ($_POST['form_search'] || $_POST['form_print']) {   - - - - - - - - - - - - - -
-   +     @@ -871,7 +588,6 @@ if ($_POST['form_search'] || $_POST['form_print']) { $row['paid']) ? " checked" : ""; - - $isdueany = sprintf("%.2f",$row['amount']) > sprintf("%.2f",$row['paid']); - - // An invoice is now due from the patient if money is owed and we are - // not waiting for insurance to pay. We no longer look at the due date - // for this. - // - $isduept = ($duncount >= 0 && $isdueany) ? " checked" : ""; - - // Skip invoices not in the desired "Due..." category. - // - if (substr($_POST['form_category'], 0, 3) == 'Due' && !$isdueany) continue; - if ($_POST['form_category'] == 'Due Ins' && ($duncount >= 0 || !$isdueany)) continue; - if ($_POST['form_category'] == 'Due Pt' && ($duncount < 0 || !$isdueany)) continue; - - $bgcolor = ((++$orow & 1) ? "#ffdddd" : "#ddddff"); - - // Determine the date of service. If this was a search parameter - // then we already know it. Or an 8-digit encounter number is - // presumed to be a date of service imported during conversion. - // Otherwise look it up in the form_encounter table. - // - $svcdate = ""; - list($pid, $encounter) = explode(".", $row['invnumber']); - // if ($form_date) { - // $svcdate = $form_date; - // } else - if (strlen($encounter) == 8) { - $svcdate = substr($encounter, 0, 4) . "-" . substr($encounter, 4, 2) . - "-" . substr($encounter, 6, 2); - } - else if ($encounter) { - $tmp = sqlQuery("SELECT date FROM form_encounter WHERE " . - "encounter = $encounter"); - $svcdate = substr($tmp['date'], 0, 10); - } - - // Get billing note to determine if customer is in collections. - // - $pdrow = sqlQuery("SELECT pd.billing_note FROM " . - "integration_mapping AS im, patient_data AS pd WHERE " . - "im.foreign_id = " . $row['custid'] . " AND " . - "im.foreign_table = 'customer' AND " . - "pd.id = im.local_id"); - $row['billnote'] = $pdrow['billing_note'] ; - $in_collections = stristr($row['billnote'], 'IN COLLECTIONS') !== false; -?> -
-   - -   - -   - -   - -   - -   - -   - -   - - - - ]' /> - IC"; ?> -
diff --git a/interface/billing/sl_receipts_report.php b/interface/billing/sl_receipts_report.php index 034990608..e01f6f733 100644 --- a/interface/billing/sl_receipts_report.php +++ b/interface/billing/sl_receipts_report.php @@ -21,7 +21,6 @@ require_once('../globals.php'); require_once($GLOBALS['srcdir'].'/patient.inc'); -require_once($GLOBALS['srcdir'].'/sql-ledger.inc'); require_once($GLOBALS['srcdir'].'/acl.inc'); require_once($GLOBALS['srcdir'].'/formatting.inc.php'); require_once($GLOBALS['srcdir'].'/options.inc.php'); @@ -50,13 +49,6 @@ require_once($GLOBALS['fileroot'].'/custom/code_types.inc.php'); if (! acl_check('acct', 'rep')) die(xl("Unauthorized access.")); - $INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2; - - if (!$INTEGRATED_AR) { - SLConnect(); - $chart_id_cash = SLQueryValue("select id from chart where accno = '$sl_cash_acc'"); - if ($sl_err) die($sl_err); - } $form_use_edate = $_POST['form_use_edate']; @@ -326,7 +318,6 @@ function sel_diagnosis() { $form_doctor = $_POST['form_doctor']; $arows = array(); - if ($INTEGRATED_AR) { $ids_to_skip = array(); $irow = 0; @@ -492,126 +483,6 @@ function sel_diagnosis() { $arows[$key]['invnumber'] = "$patient_id.$encounter_id"; $arows[$key]['irnumber'] = $row['invoice_refno']; } // end while - } // end $INTEGRATED_AR - - else { - if ($form_proc_code) { - $query = "SELECT acc_trans.amount, acc_trans.transdate, " . - "acc_trans.memo, acc_trans.project_id, acc_trans.trans_id, " . - "ar.invnumber, ar.employee_id, invoice.sellprice, invoice.qty " . - "FROM acc_trans, ar, invoice WHERE " . - "acc_trans.chart_id = $chart_id_cash AND " . - "acc_trans.memo ILIKE '$form_proc_code' AND " . - "ar.id = acc_trans.trans_id AND " . - "invoice.trans_id = acc_trans.trans_id AND " . - "invoice.serialnumber ILIKE acc_trans.memo AND " . - "invoice.sellprice >= 0.00 AND " . - "( invoice.description ILIKE 'CPT%' OR invoice.description ILIKE 'Proc%' ) AND "; - } - else { - $query = "select acc_trans.amount, acc_trans.transdate, " . - "acc_trans.memo, acc_trans.trans_id, " . - "ar.invnumber, ar.employee_id from acc_trans, ar where " . - "acc_trans.chart_id = $chart_id_cash and " . - "ar.id = acc_trans.trans_id and "; - } - - if ($form_use_edate) { - $query .= "ar.transdate >= '$form_from_date' and " . - "ar.transdate <= '$form_to_date'"; - } else { - $query .= "acc_trans.transdate >= '$form_from_date' and " . - "acc_trans.transdate <= '$form_to_date'"; - } - - $query .= " order by ar.invnumber"; - - // echo "\n"; // debugging - - $t_res = SLQuery($query); - if ($sl_err) die($sl_err); - - $docname = ""; - $docnameleft = ""; - $main_docid = 0; - $doctotal1 = 0; - $grandtotal1 = 0; - $doctotal2 = 0; - $grandtotal2 = 0; - $last_trans_id = 0; - $skipping = false; - - for ($irow = 0; $irow < SLRowCount($t_res); ++$irow) { - $row = SLGetRow($t_res, $irow); - - list($patient_id, $encounter_id) = explode(".", $row['invnumber']); - - // Under some conditions we may skip invoices that matched the SQL query. - // - if ($row['trans_id'] == $last_trans_id) { - if ($skipping) continue; - // same invoice and not skipping, do nothing. - } else { // new invoice - $skipping = false; - // If a diagnosis code was given then skip any invoices without - // that diagnosis. - if ($form_dx_code) { - if (!SLQueryValue("SELECT count(*) FROM invoice WHERE " . - "invoice.trans_id = '" . $row['trans_id'] . "' AND " . - "( invoice.description ILIKE 'ICD9:$form_dx_code %' OR " . - "invoice.serialnumber ILIKE 'ICD9:$form_dx_code' )")) - { - $skipping = true; - continue; - } - } - // If a facility was specified then skip invoices whose encounters - // do not indicate that facility. - if ($form_facility) { - $tmp = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " . - "pid = '$patient_id' AND encounter = '$encounter_id' AND " . - "facility_id = '$form_facility'"); - if (empty($tmp['count'])) { - $skipping = true; - continue; - } - } - // Find out who the practitioner is. - /*********************************************************** - $tmp = sqlQuery("SELECT users.id, users.authorized FROM forms, users WHERE " . - "forms.pid = '$patient_id' AND forms.encounter = '$encounter_id' AND " . - "forms.formdir = 'newpatient' AND users.username = forms.user"); - $main_docid = empty($tmp['id']) ? 0 : $tmp['id']; - if (empty($tmp['authorized'])) { - $tmp = sqlQuery("SELECT users.id FROM billing, users WHERE " . - "billing.pid = '$patient_id' AND billing.encounter = '$encounter_id' AND " . - "billing.activity = 1 AND billing.fee > 0 AND " . - "users.id = billing.provider_id AND users.authorized = 1 " . - "ORDER BY billing.fee DESC, billing.id ASC LIMIT 1"); - if (!empty($tmp['id'])) $main_docid = $tmp['id']; - } - ***********************************************************/ - $tmp = sqlQuery("SELECT provider_id FROM form_encounter WHERE " . - "pid = '$patient_id' AND encounter = '$encounter_id' " . - "ORDER BY id DESC LIMIT 1"); - $main_docid = $tmp['provider_id'] + 0; - - // If a practitioner was specified then skip other practitioners. - if ($form_doctor) { - if ($form_doctor != $main_docid) { - $skipping = true; - continue; - } - } - } // end new invoice - - $row['docid'] = $main_docid; - $key = sprintf("%08u%s%08u%08u%06u", $main_docid, $row['transdate'], - $patient_id, $encounter_id, $irow); - $arows[$key] = $row; - } - - } // end not $INTEGRATED_AR ksort($arows); $docid = 0; @@ -682,16 +553,11 @@ function sel_diagnosis() { "; - if ($INTEGRATED_AR) { list($patient_id, $encounter_id) = explode(".", $row['invnumber']); $tmp = sqlQuery("SELECT SUM(fee) AS sum FROM billing WHERE " . "pid = '$patient_id' AND encounter = '$encounter_id' AND " . "code_type = '$form_proc_codetype' AND code = '$form_proc_code' AND activity = 1"); bucks($tmp['sum']); - } - else { - bucks($row['sellprice'] * $row['qty']); - } echo " \n"; } ?> @@ -753,7 +619,6 @@ function sel_diagnosis() { diff --git a/interface/globals.php b/interface/globals.php index 51a249dff..da89df08d 100644 --- a/interface/globals.php +++ b/interface/globals.php @@ -389,10 +389,6 @@ if (!isset($ignoreAuth) || !$ignoreAuth) { include_once("$srcdir/auth.inc"); } -// If you do not want your accounting system to have a customer added to it -// for each insurance company, then set this to true. SQL-Ledger currently -// (2005-03-21) does nothing useful with insurance companies as customers. -$GLOBALS['insurance_companies_are_not_customers'] = true; // This is the background color to apply to form fields that are searchable. // Currently it is applicable only to the "Search or Add Patient" form. @@ -401,17 +397,6 @@ $GLOBALS['layout_search_color'] = '#ffff55'; //EMAIL SETTINGS $SMTP_Auth = !empty($GLOBALS['SMTP_USER']); -// Customize these if you are using SQL-Ledger with OpenEMR, or if you are -// going to run sl_convert.php to convert from SQL-Ledger. -// -$sl_cash_acc = '1060'; // sql-ledger account number for checking account -$sl_ar_acc = '1200'; // sql-ledger account number for accounts receivable -$sl_income_acc = '4320'; // sql-ledger account number for medical services income -$sl_services_id = 'MS'; // sql-ledger parts table id for medical services -$sl_dbname = 'sql-ledger'; // sql-ledger database name -$sl_dbuser = 'sql-ledger'; // sql-ledger database login name -$sl_dbpass = 'secret'; // sql-ledger database login password -////////////////////////////////////////////////////////////////// //module configurations $GLOBALS['baseModDir'] = "interface/modules/"; //default path of modules diff --git a/interface/main/backup.php b/interface/main/backup.php index 9fa543dd8..0771637e2 100644 --- a/interface/main/backup.php +++ b/interface/main/backup.php @@ -14,14 +14,8 @@ // * an OpenEMR database dump (gzipped) // * a phpGACL database dump (gzipped), if phpGACL is used and has // its own database -// * a SQL-Ledger database dump (gzipped), if SQL-Ledger is used -// (currently skipped on Windows servers) // * the OpenEMR web directory (.tar.gz) // * the phpGACL web directory (.tar.gz), if phpGACL is used -// * the SQL-Ledger web directory (.tar.gz), if SQL-Ledger is used -// and its web directory exists as a sister of the openemr directory -// and has the name "sql-ledger" (otherwise we do not have enough -// information to find it) // // The OpenEMR web directory is important because it includes config- // uration files, patient documents, and possible customizations, and @@ -95,7 +89,7 @@ $EXPORT_FILE = $GLOBALS['temporary_files_dir'] . "/openemr_config.sql"; $MYSQL_PATH = $GLOBALS['mysql_bin_dir']; $PERL_PATH = $GLOBALS['perl_bin_dir']; -if ($form_step == 8) { +if ($form_step == 6) { header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); @@ -222,30 +216,6 @@ if ($form_step == 2) { } if ($form_step == 3) { - if ($GLOBALS['oer_config']['ws_accounting']['enabled'] && - $GLOBALS['oer_config']['ws_accounting']['enabled'] !== 2) { - if (IS_WINDOWS) { - // Somebody may want to make this work in Windows, if they have SQL-Ledger set up. - $form_status .= xl('Skipping SQL-Ledger dump - not implemented for Windows server') . "...
"; - echo nl2br($form_status); - ++$form_step; - } - else { - $form_status .= xl('Dumping SQL-Ledger database') . "...
"; - echo nl2br($form_status); - $file_to_compress = "$BACKUP_DIR/sql-ledger.sql"; // gzip this file after creation - $cmd = "PGPASSWORD=" . escapeshellarg($sl_dbpass) . " pg_dump -U " . - escapeshellarg($sl_dbuser) . " -h localhost --format=c -f " . - "$file_to_compress " . escapeshellarg($sl_dbname); - $auto_continue = true; - } - } - else { - ++$form_step; - } -} - -if ($form_step == 4) { $form_status .= xl('Dumping OpenEMR web directory tree') . "...
"; echo nl2br($form_status); $cur_dir = getcwd(); @@ -275,7 +245,7 @@ if ($form_step == 4) { $auto_continue = true; } -if ($form_step == 5) { +if ($form_step == 4) { if ((!empty($phpgacl_location)) && ($phpgacl_location != $srcdir."/../gacl") ) { $form_status .= xl('Dumping phpGACL web directory tree') . "...
"; echo nl2br($form_status); @@ -293,28 +263,7 @@ if ($form_step == 5) { } } -if ($form_step == 6) { - if ($GLOBALS['oer_config']['ws_accounting']['enabled'] && - $GLOBALS['oer_config']['ws_accounting']['enabled'] !== 2 && - is_dir("$webserver_root/../sql-ledger")) - { - $form_status .= xl('Dumping SQL-Ledger web directory tree') . "...
"; - echo nl2br($form_status); - $cur_dir = getcwd(); - $arch_dir = $webserver_root . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "sql-ledger"; - chdir($arch_dir); - $file_list = array('.'); // archive entire directory - $arch_file = $BACKUP_DIR . DIRECTORY_SEPARATOR . "sql-ledger.tar.gz"; - if (!create_tar_archive($arch_file, "gz", $file_list)) - die(xl("An error occurred while dumping SQL-Ledger web directory tree")); - chdir($cur_dir); - $auto_continue = true; - } - else { - ++$form_step; - } -} -if ($form_step == 7) { // create the final compressed tar containing all files +if ($form_step == 5) { // create the final compressed tar containing all files $form_status .= xl('Backup file has been created. Will now send download.') . "
"; echo nl2br($form_status); $cur_dir = getcwd(); diff --git a/interface/patient_file/deleter.php b/interface/patient_file/deleter.php index fe588d866..a5276c2f9 100644 --- a/interface/patient_file/deleter.php +++ b/interface/patient_file/deleter.php @@ -205,8 +205,8 @@ function popup_close() { form_delete($row['formdir'], $row['form_id']); } row_delete("forms", "pid = '$patient'"); - - // integration_mapping is used for sql-ledger and is virtually obsolete now. + + // integration_mapping was used for sql-ledger (which is no longer supported) and is virtually obsolete now. $row = sqlQuery("SELECT id FROM patient_data WHERE pid = '$patient'"); row_delete("integration_mapping", "local_table = 'patient_data' AND " . "local_id = '" . $row['id'] . "'"); @@ -319,7 +319,6 @@ function popup_close() { else if ($billing) { if (!acl_check('acct','disc')) die("Not authorized!"); list($patient_id, $encounter_id) = explode(".", $billing); - if ($GLOBALS['oer_config']['ws_accounting']['enabled'] === 2) { sqlStatement("DELETE FROM ar_activity WHERE " . "pid = ? AND encounter = ? ", array($patient_id, $encounter_id) ); sqlStatement("DELETE ar_session FROM ar_session LEFT JOIN " . @@ -333,23 +332,6 @@ function popup_close() { sqlStatement("UPDATE form_encounter SET last_level_billed = 0, " . "last_level_closed = 0, stmt_count = 0, last_stmt_date = NULL " . "WHERE pid = '$patient_id' AND encounter = '$encounter_id'"); - } - else { - slInitialize(); - $trans_id = SLQueryValue("SELECT id FROM ar WHERE ar.invnumber = '$billing' LIMIT 1"); - if ($trans_id) { - newEvent("delete", $_SESSION['authUser'], $_SESSION['authProvider'], 1, "Invoice $billing from SQL-Ledger"); - SLQuery("DELETE FROM acc_trans WHERE trans_id = '$trans_id'"); - if ($sl_err) die($sl_err); - SLQuery("DELETE FROM invoice WHERE trans_id = '$trans_id'"); - if ($sl_err) die($sl_err); - SLQuery("DELETE FROM ar WHERE id = '$trans_id'"); - if ($sl_err) die($sl_err); - } else { - $info_msg .= "Invoice '$billing' not found!"; - } - SLClose(); - } sqlStatement("UPDATE drug_sales SET billed = 0 WHERE " . "pid = '$patient_id' AND encounter = '$encounter_id'"); updateClaim(true, $patient_id, $encounter_id, -1, -1, 1, 0, ''); // clears for rebilling diff --git a/interface/patient_file/front_payment.php b/interface/patient_file/front_payment.php index 78333c2e2..a8cf572c3 100644 --- a/interface/patient_file/front_payment.php +++ b/interface/patient_file/front_payment.php @@ -23,7 +23,6 @@ require_once("$srcdir/options.inc.php"); require_once("$srcdir/encounter_events.inc.php"); $pid = $_REQUEST['hidden_patient_code'] > 0 ? $_REQUEST['hidden_patient_code'] : $pid; -$INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2; ?> @@ -116,7 +115,6 @@ $now = time(); $today = date('Y-m-d', $now); $timestamp = date('Y-m-d H:i:s', $now); -if (!$INTEGRATED_AR) slInitialize(); // $patdata = getPatientData($pid, 'fname,lname,pubpid'); @@ -1154,59 +1152,6 @@ function make_insurance() } - // Now list previously billed visits. - - if ($INTEGRATED_AR) { - - } // end $INTEGRATED_AR - else { - // Query for all open invoices. - $query = "SELECT ar.id, ar.invnumber, ar.amount, ar.paid, " . - "ar.intnotes, ar.notes, ar.shipvia, " . - "(SELECT SUM(invoice.sellprice * invoice.qty) FROM invoice WHERE " . - "invoice.trans_id = ar.id AND invoice.sellprice > 0) AS charges, " . - "(SELECT SUM(invoice.sellprice * invoice.qty) FROM invoice WHERE " . - "invoice.trans_id = ar.id AND invoice.sellprice < 0) AS adjustments, " . - "(SELECT SUM(acc_trans.amount) FROM acc_trans WHERE " . - "acc_trans.trans_id = ar.id AND acc_trans.chart_id = ? " . - "AND acc_trans.source NOT LIKE 'Ins%') AS ptpayments " . - "FROM ar WHERE ar.invnumber LIKE ? AND " . - "ar.amount != ar.paid " . - "ORDER BY ar.invnumber"; - $ires = SLQuery($query, array($chart_id_cash,$pid."%") ); - if ($sl_err) die($sl_err); - $num_invoices = SLRowCount($ires); - - for ($ix = 0; $ix < $num_invoices; ++$ix) { - $irow = SLGetRow($ires, $ix); - - // Get encounter ID and date of service. - list($patient_id, $enc) = explode(".", $irow['invnumber']); - $tmp = sqlQuery("SELECT LEFT(date, 10) AS encdate FROM form_encounter " . - "WHERE encounter = ?", array($enc) ); - $svcdate = $tmp['encdate']; - - // Compute $duncount as in sl_eob_search.php to determine if - // this invoice is at patient responsibility. - $duncount = substr_count(strtolower($irow['intnotes']), "statement sent"); - if (! $duncount) { - $insgot = strtolower($irow['notes']); - $inseobs = strtolower($irow['shipvia']); - foreach (array('ins1', 'ins2', 'ins3') as $value) { - if (strpos($insgot, $value) !== false && - strpos($inseobs, $value) === false) - --$duncount; - } - } - - $inspaid = $irow['paid'] + $irow['ptpayments'] - $irow['adjustments']; - $balance = $irow['amount'] - $irow['paid']; - $duept = ($duncount < 0) ? 0 : $balance; - - echoLine("form_bpay[$enc]", $svcdate, $irow['charges'], - 0 - $irow['ptpayments'], $inspaid, $duept); - } - } // end not $INTEGRATED_AR // Continue with display of the data entry form. ?> @@ -1247,6 +1192,5 @@ function make_insurance() diff --git a/interface/patient_file/history/encounters.php b/interface/patient_file/history/encounters.php index d88e1e8f8..006c3a3e0 100644 --- a/interface/patient_file/history/encounters.php +++ b/interface/patient_file/history/encounters.php @@ -35,7 +35,6 @@ require_once("$srcdir/billing.inc"); require_once("$srcdir/patient.inc"); require_once("$srcdir/lists.inc"); require_once("$srcdir/acl.inc"); -require_once("$srcdir/sql-ledger.inc"); require_once("$srcdir/invoice_summary.inc.php"); require_once("$srcdir/formatting.inc.php"); require_once("../../../custom/code_types.inc.php"); @@ -46,8 +45,6 @@ require_once("$srcdir/formdata.inc.php"); // case we only display encounters that are linked to the specified issue. $issue = empty($_GET['issue']) ? 0 : 0 + $_GET['issue']; - $accounting_enabled = $GLOBALS['oer_config']['ws_accounting']['enabled']; - $INTEGRATED_AR = $accounting_enabled === 2; //maximum number of encounter entries to display on this page: // $N = 12; @@ -366,7 +363,7 @@ $getStringForPage="&pagesize=".attr($pagesize)."&pagestart=".attr($pagestart); - + @@ -451,7 +448,6 @@ if(($pagesize>0) && ($pagestart+$pagesize <= $numRes)) $res4 = sqlStatement($query, $sqlBindArray); -if ($billing_view && $accounting_enabled && !$INTEGRATED_AR) SLConnect(); while ($result4 = sqlFetchArray($res4)) { @@ -629,18 +625,11 @@ while ($result4 = sqlFetchArray($res4)) { $arinvoice = array(); $arlinkbeg = ""; $arlinkend = ""; - if ($billing_view && $accounting_enabled) { - if ($INTEGRATED_AR) { + if ($billing_view) { $tmp = sqlQuery("SELECT id FROM form_encounter WHERE " . "pid = ? AND encounter = ?", array($pid,$result4['encounter']) ); $arid = 0 + $tmp['id']; if ($arid) $arinvoice = ar_get_invoice_summary($pid, $result4['encounter'], true); - } - else { - $arid = SLQueryValue("SELECT id FROM ar WHERE invnumber = " . - "'$pid.{$result4['encounter']}'"); - if ($arid) $arinvoice = get_invoice_summary($arid, true); - } if ($arid) { $arlinkbeg = " $val) { if ($binfo[0]) { for ($i = 0; $i < 5; ++$i) $binfo[$i] .= '
'; @@ -741,11 +730,7 @@ while ($result4 = sqlFetchArray($res4)) { if ($auth_demo) { $responsible = -1; if ($arid) { - if ($INTEGRATED_AR) { $responsible = ar_responsible_party($pid, $result4['encounter']); - } else { - $responsible = responsible_party($arid); - } } $subresult5 = getInsuranceDataByDate($pid, $raw_encounter_date, "primary"); if ($subresult5 && $subresult5{"provider_name"}) { @@ -781,7 +766,6 @@ while ($result4 = sqlFetchArray($res4)) { } // end while -if ($billing_view && $accounting_enabled && !$INTEGRATED_AR) SLClose(); // Dump remaining document lines if count not exceeded. while ($drow /* && $count <= $N */) { diff --git a/interface/patient_file/pos_checkout.php b/interface/patient_file/pos_checkout.php index 2cd242560..6c70503f7 100644 --- a/interface/patient_file/pos_checkout.php +++ b/interface/patient_file/pos_checkout.php @@ -59,7 +59,6 @@ require_once("../globals.php"); require_once("$srcdir/acl.inc"); require_once("$srcdir/patient.inc"); require_once("$srcdir/billing.inc"); -require_once("$srcdir/sql-ledger.inc"); require_once("$srcdir/freeb/xmlrpc.inc"); require_once("$srcdir/freeb/xmlrpcs.inc"); require_once("$srcdir/formatting.inc.php"); @@ -68,8 +67,6 @@ require_once("../../custom/code_types.inc.php"); $currdecimals = $GLOBALS['currency_decimals']; -$INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2; - $details = empty($_GET['details']) ? 0 : 1; $patient_id = empty($_GET['ptid']) ? $pid : 0 + $_GET['ptid']; @@ -288,7 +285,7 @@ function receiptPaymentLine($paydate, $amount, $description='') { // or for the encounter specified as a GET parameter. // function generate_receipt($patient_id, $encounter=0) { - global $sl_err, $sl_cash_acc, $css_header, $details, $INTEGRATED_AR; + global $sl_err, $sl_cash_acc, $css_header, $details; // Get details for what we guess is the primary facility. $frow = sqlQuery("SELECT * FROM facility " . @@ -299,7 +296,6 @@ function generate_receipt($patient_id, $encounter=0) { // Get the most recent invoice data or that for the specified encounter. // // Adding a provider check so that their info can be displayed on receipts - if ($INTEGRATED_AR) { if ($encounter) { $ferow = sqlQuery("SELECT id, date, encounter, provider_id FROM form_encounter " . "WHERE pid = ? AND encounter = ?", array($patient_id,$encounter) ); @@ -325,36 +321,6 @@ function generate_receipt($patient_id, $encounter=0) { $providerrow = sqlQuery("SELECT fname, mname, lname, title, street, streetb, " . "city, state, zip, phone, fax FROM users WHERE id = ?", array($encprovider) ); } - } - else { - SLConnect(); - // - $arres = SLQuery("SELECT * FROM ar WHERE " . - "invnumber LIKE '$patient_id.%' " . - "ORDER BY id DESC LIMIT 1"); - if ($sl_err) die(text($sl_err)); - if (!SLRowCount($arres)) die(xlt("This patient has no activity.")); - $arrow = SLGetRow($arres, 0); - // - $trans_id = $arrow['id']; - // - // Determine the date of service. An 8-digit encounter number is - // presumed to be a date of service imported during conversion or - // associated with prescriptions only. Otherwise look it up in the - // form_encounter table. - // - $svcdate = ""; - list($trash, $encounter) = explode(".", $arrow['invnumber']); - if (strlen($encounter) >= 8) { - $svcdate = substr($encounter, 0, 4) . "-" . substr($encounter, 4, 2) . - "-" . substr($encounter, 6, 2); - } - else if ($encounter) { - $tmp = sqlQuery("SELECT date FROM form_encounter WHERE " . - "encounter = ?", array($encounter) ); - $svcdate = substr($tmp['date'], 0, 10); - } - } // end not $INTEGRATED_AR // Get invoice reference number. $encrow = sqlQuery("SELECT invoice_refno FROM form_encounter WHERE " . @@ -428,7 +394,6 @@ function generate_receipt($patient_id, $encounter=0) { @@ -498,7 +449,6 @@ function generate_receipt($patient_id, $encounter=0) {   @@ -574,7 +504,6 @@ function generate_receipt($patient_id, $encounter=0) { $value) { - list($key_newval['pid'], $key_newval['encounter']) = explode(".", $key); - $newkey = $key_newval['pid']; - $newencounter = $key_newval['encounter']; - # added this condition to handle the downloading of individual invoices (TLH) - if($_POST['form_individual'] ==1){ - $where .= " OR f.encounter = $newencounter "; - } - else - { - $where .= " OR f.pid = $newkey "; - } - } - $where .= ' )'; - } - - if ($form_date) { - if ($where) $where .= " AND "; - $date1 = substr($form_date, 0, 4) . substr($form_date, 5, 2) . - substr($form_date, 8, 2); - if ($form_to_date) { - $date2 = substr($form_to_date, 0, 4) . substr($form_to_date, 5, 2) . - substr($form_to_date, 8, 2); - $where .= "((CAST (substring(ar.invnumber from position('.' in ar.invnumber) + 1 for 8) AS integer) " . - "BETWEEN '$date1' AND '$date2')"; - $tmp = "date >= '$form_date' AND date <= '$form_to_date'"; - } - else { - // This catches old converted invoices where we have no encounters: - $where .= "(ar.invnumber LIKE '%.$date1'"; - $tmp = "date = '$form_date'"; - } - // Pick out the encounters from MySQL with the desired DOS: - $rez = sqlStatement("SELECT pid, encounter FROM form_encounter WHERE $tmp"); - while ($row = sqlFetchArray($rez)) { - $where .= " OR ar.invnumber = '" . $row['pid'] . "." . $row['encounter'] . "'"; - } - $where .= ")"; - } - - if (! $where) { - $where = "1 = 1"; - } - - // Instead of the subselects in the following query, we will call - // get_invoice_summary() in order to get data at the procedure level and - // thus decide if insurance appears to be done with each invoice. - - $query = "SELECT ar.id, ar.invnumber, ar.duedate, ar.amount, ar.paid, " . - "ar.intnotes, ar.notes, ar.shipvia, " . - "customer.id AS custid, customer.name, customer.address1, " . - "customer.city, customer.state, customer.zipcode, customer.phone " . - // ", (SELECT SUM(invoice.fxsellprice) FROM invoice WHERE " . - // "invoice.trans_id = ar.id AND invoice.fxsellprice > 0) AS charges, " . - // "(SELECT SUM(invoice.fxsellprice) FROM invoice WHERE " . - // "invoice.trans_id = ar.id AND invoice.fxsellprice < 0) AS adjustments " . - "FROM ar JOIN customer ON customer.id = ar.customer_id " . - "WHERE ( $where ) "; - if ($_POST['form_refresh'] && ! $is_all) { - $query .= "AND ar.amount != ar.paid "; - } - $query .= "ORDER BY ar.invnumber"; - - // echo "\n"; // debugging - - $t_res = SLQuery($query); - if ($sl_err) die($sl_err); - $num_invoices = SLRowCount($t_res); - - ////////////////////////////////////////////////////////////////// - - for ($irow = 0; $irow < $num_invoices; ++$irow) { - $row = SLGetRow($t_res, $irow); - - // If a facility was specified then skip invoices whose encounters - // do not indicate that facility. - if ($form_facility) { - list($patient_id, $encounter_id) = explode(".", $row['invnumber']); - $tmp = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " . - "pid = ? AND encounter = ? AND " . - "facility_id = ? ", array($patient_id, $encounter_id, $form_facility)); - if (empty($tmp['count'])) continue; - } - - if ($form_provider) { - list($patient_id, $encounter_id) = explode(".", $row['invnumber']); - $tmp = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " . - "pid = ? AND encounter = ? AND " . - "provider_id = ? ", array($patient_id, $encounter_id, $form_provider)); - - if (empty($tmp['count'])) continue; - } - - $pt_balance = sprintf("%.2f",$row['amount']) - sprintf("%.2f",$row['paid']); - - if ($_POST['form_category'] == 'Credits') { - if ($pt_balance > 0) continue; - } - - // $duncount was originally supposed to be the number of times that - // the patient was sent a statement for this invoice. - // - $duncount = substr_count(strtolower($row['intnotes']), "statement sent"); - - // But if we have not yet billed the patient, then compute $duncount as a - // negative count of the number of insurance plans for which we have not - // yet closed out insurance. Here we also compute $insname as the name of - // the insurance plan from which we are awaiting payment, and its sequence - // number $insposition (1-3). - // - $insname = ''; - $insposition = 0; - $inseobs = strtolower($row['shipvia']); - $insgot = strtolower($row['notes']); - if (! $duncount) { - foreach (array('ins1', 'ins2', 'ins3') as $value) { - $i = strpos($insgot, $value); - if ($i !== false && strpos($inseobs, $value) === false) { - --$duncount; - if (!$insname && $is_due_ins) { - $j = strpos($insgot, "\n", $i); - if (!$j) $j = strlen($insgot); - $insname = trim(substr($row['notes'], $i + 5, $j - $i - 5)); - $insposition = substr($value, 3); // 1, 2 or 3 - } - } - } - } - $row['insname'] = $insname; - - // Also get the primary insurance company name whenever there is one. - $row['ins1'] = ''; - $i = strpos($insgot, 'ins1'); - if ($i !== false) { - $j = strpos($insgot, "\n", $i); - if (!$j) $j = strlen($insgot); - $row['ins1'] = trim(substr($row['notes'], $i + 5, $j - $i - 5)); - } - - // An invoice is now due from the patient if money is owed and we are - // not waiting for insurance to pay. We no longer look at the due date - // for this. - // - $isduept = ($duncount >= 0) ? " checked" : ""; - - // Skip invoices not in the desired "Due..." category. - // - if ($is_due_ins && $duncount >= 0) continue; - if ($is_due_pt && $duncount < 0) continue; - - $row['duncount'] = $duncount; - - // Determine the date of service. An 8-digit encounter number is - // presumed to be a date of service imported during conversion. - // Otherwise look it up in the form_encounter table. - // - $svcdate = ""; - list($pid, $encounter) = explode(".", $row['invnumber']); - if (strlen($encounter) == 8) { - $svcdate = substr($encounter, 0, 4) . "-" . substr($encounter, 4, 2) . - "-" . substr($encounter, 6, 2); - } - else if ($encounter) { - $tmp = sqlQuery("SELECT date FROM form_encounter WHERE " . - "encounter = ? ", array($encounter)); - $svcdate = substr($tmp['date'], 0, 10); - } - - $row['dos'] = $svcdate; - - // This computes the invoice's total original charges and adjustments, - // date of last activity, and determines if insurance has responded to - // all billing items. - // - $invlines = get_invoice_summary($row['id'], true); - $row['charges'] = 0; - $row['adjustments'] = 0; - $ins_seems_done = true; - $ladate = $svcdate; - foreach ($invlines as $key => $value) { - $row['charges'] += $value['chg'] + $value['adj']; - $row['adjustments'] += 0 - $value['adj']; - foreach ($value['dtl'] as $dkey => $dvalue) { - $dtldate = trim(substr($dkey, 0, 10)); - if ($dtldate && $dtldate > $ladate) $ladate = $dtldate; - } - $lckey = strtolower($key); - if ($lckey == 'co-pay' || $lckey == 'claim') continue; - if (count($value['dtl']) <= 1) $ins_seems_done = false; - } - $row['billing_errmsg'] = ''; - if ($is_due_ins && strpos($inseobs, 'ins1') === false && $ins_seems_done) - $row['billing_errmsg'] = 'Ins1 seems done'; - else if (strpos($inseobs, 'ins1') !== false && !$ins_seems_done) - $row['billing_errmsg'] = 'Ins1 seems not done'; - - $row['ladate'] = $ladate; - - // Compute number of days since last activity. - $latime = mktime(0, 0, 0, substr($ladate, 5, 2), - substr($ladate, 8, 2), substr($ladate, 0, 4)); - $row['inactive_days'] = floor((time() - $latime) / (60 * 60 * 24)); - - $pdrow = sqlQuery("SELECT pd.fname, pd.lname, pd.mname, pd.ss, " . - "pd.billing_note, pd.pid, pd.pubpid, pd.DOB, " . - "CONCAT(u.lname, ', ', u.fname) AS referrer FROM " . - "integration_mapping AS im, patient_data AS pd " . - "LEFT OUTER JOIN users AS u ON u.id = pd.ref_providerID " . - "WHERE im.foreign_id = ? AND " . - "im.foreign_table = 'customer' AND " . - "pd.id = im.local_id", array($row['custid'])); - - $row['ss'] = $pdrow['ss']; - $row['DOB'] = $pdrow['DOB']; - $row['pubpid'] = $pdrow['pubpid']; - $row['billnote'] = $pdrow['billing_note']; - $row['referrer'] = $pdrow['referrer']; - - $ptname = $pdrow['lname'] . ", " . $pdrow['fname']; - if ($pdrow['mname']) $ptname .= " " . substr($pdrow['mname'], 0, 1); - - // Look up insurance policy number if we need it. - if ($form_cb_policy) { - $patient_id = $pdrow['pid']; - $instype = ($insposition == 2) ? 'secondary' : (($insposition == 3) ? 'tertiary' : 'primary'); - $insrow = sqlQuery("SELECT policy_number FROM insurance_data WHERE " . - "pid = ? AND type = ? AND date <= ? " . - "ORDER BY date DESC LIMIT 1", array($patient_id, $instype, $svcdate)); - $row['policy'] = $insrow['policy_number']; - } - - $rows[$insname . '|' . $ptname . '|' . $encounter] = $row; - } // end for - } // end not $INTEGRATED_AR ksort($rows); @@ -1426,7 +1183,6 @@ if ($_POST['form_refresh'] || $_POST['form_export'] || $_POST['form_csvexport']) } } // end if form_refresh -if (!$INTEGRATED_AR) SLClose(); if (!$_POST['form_csvexport']) { if (!$_POST['form_export']) { diff --git a/interface/reports/inventory_activity.php b/interface/reports/inventory_activity.php index 15569abd4..d5a00bcf3 100644 --- a/interface/reports/inventory_activity.php +++ b/interface/reports/inventory_activity.php @@ -26,7 +26,6 @@ $fake_register_globals=false; require_once("../globals.php"); require_once("$srcdir/patient.inc"); -require_once("$srcdir/sql-ledger.inc"); require_once("$srcdir/acl.inc"); require_once("$srcdir/formatting.inc.php"); diff --git a/interface/reports/receipts_by_method_report.php b/interface/reports/receipts_by_method_report.php index 5ead091a7..680105bc7 100644 --- a/interface/reports/receipts_by_method_report.php +++ b/interface/reports/receipts_by_method_report.php @@ -17,7 +17,6 @@ require_once("../globals.php"); require_once("$srcdir/patient.inc"); -require_once("$srcdir/sql-ledger.inc"); require_once("$srcdir/acl.inc"); require_once("$srcdir/formatting.inc.php"); require_once "$srcdir/options.inc.php"; @@ -165,9 +164,6 @@ function payerCmp($a, $b) { if (! acl_check('acct', 'rep')) die(xl("Unauthorized access.")); -$INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2; - -if (!$INTEGRATED_AR) SLConnect(); $form_from_date = fixDate($_POST['form_from_date'], date('Y-m-d')); $form_to_date = fixDate($_POST['form_to_date'] , date('Y-m-d')); @@ -388,12 +384,6 @@ function sel_procedure() { = '$from_date' AND " . - "ar.transdate <= '$to_date'"; - } else { - $query .= "acc_trans.transdate >= '$from_date' AND " . - "acc_trans.transdate <= '$to_date'"; - } - $query .= " ORDER BY source, acc_trans.transdate, ar.invnumber, acc_trans.memo"; - - // echo "\n"; - - $t_res = SLQuery($query); - if ($sl_err) die($sl_err); - - for ($irow = 0; $irow < SLRowCount($t_res); ++$irow) { - $row = SLGetRow($t_res, $irow); - list($patient_id, $encounter_id) = explode(".", $row['invnumber']); - - // If a facility was specified then skip invoices whose encounters - // do not indicate that facility. - if ($form_facility) { - $tmp = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " . - "pid = '$patient_id' AND encounter = '$encounter_id' AND " . - "facility_id = '$form_facility'"); - if (empty($tmp['count'])) continue; - } - - $rowpayamount = 0 - $row['amount']; - $rowadjamount = 0; - if ($row['chart_id'] == $chart_id_income) { - $rowadjamount = $rowpayamount; - $rowpayamount = 0; - } - - // Compute reporting key: insurance company name or payment method. - $payer_type = 0; // will be 0=pt, 1=ins1, 2=ins2 or 3=ins3 - if ($form_report_by == '1') { - $rowmethod = ''; - $rowsrc = strtolower($row['source']); - $insgot = strtolower($row['notes']); - foreach (array('ins1', 'ins2', 'ins3') as $value) { - if (strpos($rowsrc, $value) !== false) { - $i = strpos($insgot, $value); - if ($i !== false) { - $j = strpos($insgot, "\n", $i); - if (!$j) $j = strlen($insgot); - $payer_type = 0 + substr($value, 3); - $rowmethod = trim(substr($row['notes'], $i + 5, $j - $i - 5)); - break; - } - } - } // end foreach - } // end reporting by payer - else { - $rowmethod = trim($row['source']); - if ($form_report_by != '3') { - // Extract only the first word as the payment method because any - // following text will be some petty detail like a check number. - $rowmethod = substr($rowmethod, 0, strcspn($rowmethod, ' /')); - } - } // end reporting by method - - thisLineItem($patient_id, $encounter_id, $row['memo'], $row['transdate'], - $rowmethod, $rowpayamount, $rowadjamount, $payer_type); - } // end for - } // end not $INTEGRATED_AR // Not payer summary. if ($form_report_by != '1' || $_POST['form_details']) { @@ -662,7 +572,6 @@ if ($_POST['form_refresh']) { diff --git a/interface/reports/sales_by_item.php b/interface/reports/sales_by_item.php index 785c07835..c52d7cecd 100644 --- a/interface/reports/sales_by_item.php +++ b/interface/reports/sales_by_item.php @@ -1,9 +1,8 @@ + * Copyright (C) 2015-2016 Terry Hill * Copyright (C) 2006-2010 Rod Roark * * LICENSE: This program is free software; you can redistribute it and/or @@ -27,7 +26,6 @@ $fake_register_globals=false; require_once("../globals.php"); require_once("$srcdir/patient.inc"); -require_once("$srcdir/sql-ledger.inc"); require_once("$srcdir/acl.inc"); require_once("$srcdir/formatting.inc.php"); require_once "$srcdir/options.inc.php"; @@ -230,9 +228,6 @@ function thisLineItem($patient_id, $encounter_id, $rowcat, $description, $transd if (! acl_check('acct', 'rep')) die(xl("Unauthorized access.")); - $INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2; - - if (!$INTEGRATED_AR) SLConnect(); $form_from_date = fixDate($_POST['form_from_date'], date('Y-m-d')); $form_to_date = fixDate($_POST['form_to_date'] , date('Y-m-d')); @@ -492,7 +487,6 @@ function thisLineItem($patient_id, $encounter_id, $rowcat, $description, $transd $grandtotal = 0; $grandqty = 0; - if ($INTEGRATED_AR) { $sqlBindArray = array(); $query = "SELECT b.fee, b.pid, b.encounter, b.code_type, b.code, b.units, " . "b.code_text, fe.date, fe.facility_id, fe.provider_id, fe.invoice_refno, lo.title " . @@ -548,31 +542,6 @@ function thisLineItem($patient_id, $encounter_id, $rowcat, $description, $transd thisLineItem($row['pid'], $row['encounter'], xl('Products'), $row['name'], substr($row['date'], 0, 10), $row['quantity'], $row['fee'], $row['invoice_refno']); } - } - else { - $query = "SELECT ar.invnumber, ar.transdate, " . - "invoice.description, invoice.qty, invoice.sellprice " . - "FROM ar, invoice WHERE " . - "ar.transdate >= '$from_date' AND ar.transdate <= '$to_date' " . - "AND invoice.trans_id = ar.id " . - "ORDER BY invoice.description, ar.transdate, ar.id"; - $t_res = SLQuery($query); - if ($sl_err) die($sl_err); - for ($irow = 0; $irow < SLRowCount($t_res); ++$irow) { - $row = SLGetRow($t_res, $irow); - list($patient_id, $encounter_id) = explode(".", $row['invnumber']); - // If a facility was specified then skip invoices whose encounters - // do not indicate that facility. - if ($form_facility) { - $tmp = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " . - "pid = '$patient_id' AND encounter = '$encounter_id' AND " . - "facility_id = '$form_facility'"); - if (empty($tmp['count'])) continue; - } - thisLineItem($patient_id, $encounter_id, '', $row['description'], - $row['transdate'], $row['qty'], $row['sellprice'] * $row['qty']); - } // end for - } // end not $INTEGRATED_AR if ($_POST['form_csvexport']) { if (! $_POST['form_details']) { @@ -657,7 +626,6 @@ function thisLineItem($patient_id, $encounter_id, $rowcat, $description, $transd } // End not csv export } - if (!$INTEGRATED_AR) SLClose(); if (! $_POST['form_csvexport']) { if($_POST['form_refresh']){ diff --git a/interface/reports/svc_code_financial_report.php b/interface/reports/svc_code_financial_report.php index 768d32450..4204442f5 100644 --- a/interface/reports/svc_code_financial_report.php +++ b/interface/reports/svc_code_financial_report.php @@ -31,7 +31,6 @@ $fake_register_globals=false; require_once("../globals.php"); require_once("$srcdir/patient.inc"); -require_once("$srcdir/sql-ledger.inc"); require_once("$srcdir/acl.inc"); require_once("$srcdir/formatting.inc.php"); require_once "$srcdir/options.inc.php"; @@ -47,10 +46,6 @@ $grand_total_amt_balance = 0; if (! acl_check('acct', 'rep')) die(xlt("Unauthorized access.")); - $INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2; - - if (!$INTEGRATED_AR) SLConnect(); - $form_from_date = fixDate($_POST['form_from_date'], date('Y-m-d')); $form_to_date = fixDate($_POST['form_to_date'] , date('Y-m-d')); $form_facility = $_POST['form_facility']; @@ -219,7 +214,6 @@ $grand_total_amt_balance = 0; $from_date = $form_from_date; $to_date = $form_to_date; $sqlBindArray = array(); - if ($INTEGRATED_AR) { $query = "select b.code,sum(b.units) as units,sum(b.fee) as billed,sum(ar_act.paid) as PaidAmount, " . "sum(ar_act.adjust) as AdjustAmount,(sum(b.fee)-(sum(ar_act.paid)+sum(ar_act.adjust))) as Balance, " . "c.financial_reporting " . @@ -341,7 +335,6 @@ $bgcolor = ((++$orow & 1) ? "#ffdddd" : "#ddddff"); invoice = array(); if ($this->payerSequence() != 'P') { - if ($GLOBALS['oer_config']['ws_accounting']['enabled'] === 2) { $this->invoice = ar_get_invoice_summary($this->pid, $this->encounter_id, true); - } - else if ($GLOBALS['oer_config']['ws_accounting']['enabled']) { - SLConnect(); - $arres = SLQuery("select id from ar where invnumber = " . - "'{$this->pid}.{$this->encounter_id}'"); - if ($sl_err) die($sl_err); - $arrow = SLGetRow($arres, 0); - if ($arrow) { - $this->invoice = get_invoice_summary($arrow['id'], true); - } - SLClose(); - } // Secondary claims might not have modifiers in SQL-Ledger data. // In that case, note that we should not try to match on them. $this->using_modifiers = false; @@ -310,8 +296,8 @@ class Claim { // payments and "hard" adjustments up to this payer. $ptresp = $this->invoice[$code]['chg'] + $this->invoice[$code]['adj']; foreach ($this->invoice[$code]['dtl'] as $key => $value) { - if (isset($value['plv'])) { - // New method; plv (from ar_activity.payer_type) exists to + + // plv (from ar_activity.payer_type) exists to // indicate the payer level. if (isset($value['pmt']) && $value['pmt'] != 0) { if ($value['plv'] > 0 && $value['plv'] <= $insnumber) @@ -325,17 +311,6 @@ class Claim { $msp = isset( $value['msp'] ) ? $value['msp'] : null; // record the reason for adjustment } - else { - // Old method: With SQL-Ledger payer level was stored in the memo. - if (preg_match("/^Ins(\d)/i", $value['src'], $tmp)) { - if ($tmp[1] <= $insnumber) $ptresp -= $value['pmt']; - } - else if (trim(substr($key, 0, 10))) { // not an adjustment if no date - if (!preg_match("/Ins(\d)/i", $value['rsn'], $tmp) || $tmp[1] <= $insnumber) - $ptresp += $value['chg']; // adjustments are negative charges - } - } - } if ($ptresp < 0) $ptresp = 0; // we may be insane but try to hide it // Main loop, to extract adjustments for this payer and procedure. @@ -423,19 +398,12 @@ class Claim { $thispaidanything = 0; foreach($this->invoice as $codekey => $codeval) { foreach ($codeval['dtl'] as $key => $value) { - if (isset($value['plv'])) { - // New method; plv exists to indicate the payer level. + // plv exists to indicate the payer level. if ($value['plv'] == $insnumber) { $thispaidanything += $value['pmt']; } } - else { - if (preg_match("/$inslabel/i", $value['src'], $tmp)) { - $thispaidanything += $value['pmt']; - } - } } - } // Allocate any unknown patient responsibility by guessing if the // deductible has been satisfied. @@ -475,22 +443,13 @@ class Claim { foreach($this->invoice as $codekey => $codeval) { if ($code && strcmp($codekey,$code) != 0) continue; foreach ($codeval['dtl'] as $key => $value) { - if (isset($value['plv'])) { - // New method; plv (from ar_activity.payer_type) exists to + // plv (from ar_activity.payer_type) exists to // indicate the payer level. if ($value['plv'] == $insnumber) { if (!$date) $date = str_replace('-', '', trim(substr($key, 0, 10))); $paytotal += $value['pmt']; } } - else { - // Old method: With SQL-Ledger payer level was stored in the memo. - if (preg_match("/$inslabel/i", $value['src'], $tmp)) { - if (!$date) $date = str_replace('-', '', trim(substr($key, 0, 10))); - $paytotal += $value['pmt']; - } - } - } $aarr = $this->payerAdjustments($ins, $codekey); foreach ($aarr as $a) { if (strcmp($a[1],'PR') != 0) $adjtotal += $a[3]; @@ -510,19 +469,11 @@ class Claim { $amount = 0; foreach($this->invoice as $codekey => $codeval) { foreach ($codeval['dtl'] as $key => $value) { - if (isset($value['plv'])) { - // New method; plv exists to indicate the payer level. + // plv exists to indicate the payer level. if ($value['plv'] == 0) { // 0 indicates patient $amount += $value['pmt']; } } - else { - // Old method: With SQL-Ledger payer level was stored in the memo. - if (!preg_match("/Ins/i", $value['src'], $tmp)) { - $amount += $value['pmt']; - } - } - } } return sprintf('%.2f', $amount); } diff --git a/library/invoice_summary.inc.php b/library/invoice_summary.inc.php index 6d95038d7..f727b74da 100644 --- a/library/invoice_summary.inc.php +++ b/library/invoice_summary.inc.php @@ -32,103 +32,8 @@ require_once("sl_eob.inc.php"); require_once(dirname(__FILE__) . "/../custom/code_types.inc.php"); -function get_invoice_summary($trans_id, $with_detail = false) { - global $sl_err, $sl_cash_acc; - $codes = array(); - - $chart_id_cash = SLQueryValue("select id from chart where accno = '$sl_cash_acc'"); - if ($sl_err) die($sl_err); - if (! $chart_id_cash) die("There is no COA entry for cash account '$sl_cash_acc'"); - - // Request all cash entries belonging to the invoice. - $atres = SLQuery("select * from acc_trans where trans_id = $trans_id and chart_id = $chart_id_cash"); - if ($sl_err) die($sl_err); - - // Deduct payments for each procedure code from the respective balance owed. - $keysuffix = 5000; - for ($irow = 0; $irow < SLRowCount($atres); ++$irow) { - $row = SLGetRow($atres, $irow); - $code = strtoupper($row['memo']); - $ins_id = $row['project_id']; - if (! $code) $code = "Unknown"; - $amount = $row['amount']; - $codes[$code]['bal'] += $amount; // amount is negative for a payment - if ($ins_id) - $codes[$code]['ins'] = $ins_id; - - // Add the details if they want 'em. - if ($with_detail) { - if (! $codes[$code]['dtl']) $codes[$code]['dtl'] = array(); - $tmpkey = $row['transdate'] . $keysuffix++; - $tmp = array(); - $tmp['pmt'] = 0 - $amount; - $tmp['src'] = $row['source']; - if ($ins_id) $tmp['ins'] = $ins_id; - $codes[$code]['dtl'][$tmpkey] = $tmp; - } - } - - // Request all line items with money or adjustment reasons belonging - // to the invoice. - $inres = SLQuery("SELECT * FROM invoice WHERE trans_id = $trans_id AND " . - "( sellprice != 0 OR description LIKE 'Adjustment%' OR serialnumber = 'Claim' )"); - if ($sl_err) die($sl_err); - - // Add charges and adjustments for each procedure code into its total and balance. - $keysuffix = 1000; - for ($irow = 0; $irow < SLRowCount($inres); ++$irow) { - $row = SLGetRow($inres, $irow); - // $amount = $row['sellprice']; - $amount = sprintf('%01.2f', $row['sellprice'] * $row['qty']); - $ins_id = $row['project_id']; - - $code = "Unknown"; - if ($row['serialnumber'] == 'Claim') { - $code = 'Claim'; - } - else if (preg_match("/([A-Za-z0-9]\d\d\S*)/", $row['serialnumber'], $matches)) { - $code = strtoupper($matches[1]); - } - else if (preg_match("/([A-Za-z0-9]\d\d\S*)/", $row['description'], $matches)) { - $code = strtoupper($matches[1]); - } - else if (preg_match("/^TAX:/", $row['description'])) { - $code = 'TAX'; - } - - $codes[$code]['chg'] += $amount; - $codes[$code]['bal'] += $amount; - if ($amount < 0) $codes[$code]['adj'] -= $amount; - - if ($ins_id) - $codes[$code]['ins'] = $ins_id; - - // Add the details if they want 'em. - if ($with_detail) { - if (! $codes[$code]['dtl']) $codes[$code]['dtl'] = array(); - if (preg_match("/^Adjustment\s*(\S*)\s*(.*)/", $row['description'], $matches)) { - $tmpkey = str_pad($matches[1], 10) . $keysuffix++; - $tmp = array(); - $tmp['chg'] = $amount; - $tmp['rsn'] = $matches[2]; - if ($ins_id) $tmp['ins'] = $ins_id; - $codes[$code]['dtl'][$tmpkey] = $tmp; - } - else { - $tmpkey = " " . $keysuffix++; - $tmp = array(); - $tmp['chg'] = $amount; - if ($code == 'TAX') $tmp['dsc'] = substr($row['description'], 4); - $codes[$code]['dtl'][$tmpkey] = $tmp; - } - } - } - - return $codes; -} - -// Like the above, but for Integrated A/R. +// for Integrated A/R. // function ar_get_invoice_summary($patient_id, $encounter_id, $with_detail = false) { $codes = array(); @@ -249,25 +154,7 @@ function ar_get_invoice_summary($patient_id, $encounter_id, $with_detail = false // This determines the party from whom payment is currently expected. // Returns: -1=Nobody, 0=Patient, 1=Ins1, 2=Ins2, 3=Ins3. -// -function responsible_party($trans_id) { - global $sl_err; - $arres = SLQuery("select * from ar where id = $trans_id"); - if ($sl_err) die($sl_err); - $arrow = SLGetRow($arres, 0); - if (! $arrow) die(xl("There is no match for invoice id = ") . $trans_id); - if ($arrow['paid'] >= $arrow['netamount']) return -1; - $insgot = strtolower($arrow['notes']); - $insdone = strtolower($arrow['shipvia']); - for ($i = 1; $i <= 3; ++$i) { - $lcvalue = "ins$i"; - if (strpos($insgot, $lcvalue) !== false && strpos($insdone, $lcvalue) === false) - return $i; - } - return 0; -} - -// As above but for Integrated A/R. +// for Integrated A/R. // function ar_responsible_party($patient_id, $encounter_id) { $row = sqlQuery("SELECT date, last_level_billed, last_level_closed " . diff --git a/library/sl_eob.inc.php b/library/sl_eob.inc.php dissimilarity index 64% index f47533f26..c56fd314d 100644 --- a/library/sl_eob.inc.php +++ b/library/sl_eob.inc.php @@ -1,668 +1,260 @@ - - // - // This program is free software; you can redistribute it and/or - // modify it under the terms of the GNU General Public License - // as published by the Free Software Foundation; either version 2 - // of the License, or (at your option) any later version. - - include_once("patient.inc"); - include_once("billing.inc"); - - if ($GLOBALS['oer_config']['ws_accounting']['enabled'] !== 2) { - include_once("sql-ledger.inc"); - include_once("invoice_summary.inc.php"); - } - - $chart_id_cash = 0; - $chart_id_ar = 0; - $chart_id_income = 0; - $services_id = 0; - - function slInitialize() { - if ($GLOBALS['oer_config']['ws_accounting']['enabled'] === 2) return; - - global $chart_id_cash, $chart_id_ar, $chart_id_income, $services_id; - global $sl_cash_acc, $sl_ar_acc, $sl_income_acc, $sl_services_id; - - SLConnect(); - - $chart_id_cash = SLQueryValue("select id from chart where accno = '$sl_cash_acc'"); - if ($sl_err) die($sl_err); - if (! $chart_id_cash) die(xl("There is no COA entry for cash account ") . "'$sl_cash_acc'"); - - $chart_id_ar = SLQueryValue("select id from chart where accno = '$sl_ar_acc'"); - if ($sl_err) die($sl_err); - if (! $chart_id_ar) die(xl("There is no COA entry for AR account ") . "'$sl_ar_acc'"); - - $chart_id_income = SLQueryValue("select id from chart where accno = '$sl_income_acc'"); - if ($sl_err) die($sl_err); - if (! $chart_id_income) die(xl("There is no COA entry for income account ") . "'$sl_income_acc'"); - - $services_id = SLQueryValue("select id from parts where partnumber = '$sl_services_id'"); - if ($sl_err) die($sl_err); - if (! $services_id) die(xl("There is no parts entry for services ID ") . "'$sl_services_id'"); - } - - function slTerminate() { - if ($GLOBALS['oer_config']['ws_accounting']['enabled'] === 2) return; - SLClose(); - } - - // Try to figure out our invoice number (pid.encounter) from the - // claim ID and other stuff in the ERA. This should be straightforward - // except that some payers mangle the claim ID that we give them. - // - function slInvoiceNumber(&$out) { - $invnumber = $out['our_claim_id']; - $atmp = preg_split('/[ -]/', $invnumber); - $acount = count($atmp); - - $pid = 0; - $encounter = 0; - if ($acount == 2) { - $pid = $atmp[0]; - $encounter = $atmp[1]; - } - else if ($acount == 3) { - $pid = $atmp[0]; - $brow = sqlQuery("SELECT encounter FROM billing WHERE " . - "pid = '$pid' AND encounter = '" . $atmp[1] . "' AND activity = 1"); - - $encounter = $brow['encounter']; - } - else if ($acount == 1) { - $pres = sqlStatement("SELECT pid FROM patient_data WHERE " . - "lname LIKE '" . addslashes($out['patient_lname']) . "' AND " . - "fname LIKE '" . addslashes($out['patient_fname']) . "' " . - "ORDER BY pid DESC"); - while ($prow = sqlFetchArray($pres)) { - if (strpos($invnumber, $prow['pid']) === 0) { - $pid = $prow['pid']; - $encounter = substr($invnumber, strlen($pid)); - break; - } - } - } - - if ($pid && $encounter) $invnumber = "$pid.$encounter"; - return array($pid, $encounter, $invnumber); - } - - // Insert a row into the acc_trans table. - // This should never be called if SQL-Ledger is not used. - // - function slAddTransaction($invid, $chartid, $amount, $date, $source, $memo, $insplan, $debug) { - global $sl_err; - if ($GLOBALS['oer_config']['ws_accounting']['enabled'] === 2) - die("Internal error calling slAddTransaction()"); - $date = fixDate($date); - $query = "INSERT INTO acc_trans ( " . - "trans_id, " . - "chart_id, " . - "amount, " . - "transdate, " . - "source, " . - "project_id, " . - "memo " . - ") VALUES ( " . - "$invid, " . // trans_id - "$chartid, " . // chart_id - "$amount, " . // amount - "'$date', " . // transdate - "'$source', " . // source - "$insplan, " . // project_id - "'$memo' " . // memo - ")"; - if ($debug) { - echo $query . "
\n"; - } else { - SLQuery($query); - if ($sl_err) die($sl_err); - } - } - - // Insert a row into the invoice table. - // This should never be called if SQL-Ledger is not used. - // - function slAddLineItem($invid, $serialnumber, $amount, $units, $insplan, $description, $debug) { - global $sl_err, $services_id; - if ($GLOBALS['oer_config']['ws_accounting']['enabled'] === 2) - die("Internal error calling slAddLineItem()"); - $units = max(1, intval($units)); - $price = $amount / $units; - $tmp = sprintf("%01.2f", $price); - if (abs($price - $tmp) < 0.000001) $price = $tmp; - $query = "INSERT INTO invoice ( " . - "trans_id, " . - "parts_id, " . - "description, " . - "qty, " . - "allocated, " . - "sellprice, " . - "fxsellprice, " . - "discount, " . - "unit, " . - "project_id, " . - "serialnumber " . - ") VALUES ( " . - "$invid, " . // trans_id - "$services_id, " . // parts_id - "'$description', " . // description - "$units, " . // qty - "0, " . // allocated - "$price, " . // sellprice - "$price, " . // fxsellprice - "0, " . // discount - "'', " . // unit - "$insplan, " . // project_id - "'$serialnumber'" . // serialnumber - ")"; - if ($debug) { - echo $query . "
\n"; - } else { - SLQuery($query); - if ($sl_err) die($sl_err); - } - } - - // Update totals and payment date in the invoice header. Dollar amounts are - // stored as double precision floats so we have to be careful about rounding. - // This should never be called if SQL-Ledger is not used. - // - function slUpdateAR($invid, $amount, $paid = 0, $paydate = "", $debug) { - global $sl_err; - if ($GLOBALS['oer_config']['ws_accounting']['enabled'] === 2) - die("Internal error calling slUpdateAR()"); - $paydate = fixDate($paydate); - $query = "UPDATE ar SET amount = round(CAST (amount AS numeric) + $amount, 2), " . - "netamount = round(CAST (netamount AS numeric) + $amount, 2)"; - if ($paid) $query .= ", paid = round(CAST (paid AS numeric) + $paid, 2), datepaid = '$paydate'"; - $query .= " WHERE id = $invid"; - if ($debug) { - echo $query . "
\n"; - } else { - SLQuery($query); - if ($sl_err) die($sl_err); - } - } - - // This gets a posting session ID. If the payer ID is not 0 and a matching - // session already exists, then its ID is returned. Otherwise a new session - // is created. - // - function arGetSession($payer_id, $reference, $check_date, $deposit_date='', $pay_total=0) { - if (empty($deposit_date)) $deposit_date = $check_date; - if ($payer_id) { - $row = sqlQuery("SELECT session_id FROM ar_session WHERE " . - "payer_id = '$payer_id' AND reference = '$reference' AND " . - "check_date = '$check_date' AND deposit_date = '$deposit_date' " . - "ORDER BY session_id DESC LIMIT 1"); - if (!empty($row['session_id'])) return $row['session_id']; - } - return sqlInsert("INSERT INTO ar_session ( " . - "payer_id, user_id, reference, check_date, deposit_date, pay_total " . - ") VALUES ( " . - "'$payer_id', " . - "'" . $_SESSION['authUserID'] . "', " . - "'$reference', " . - "'$check_date', " . - "'$deposit_date', " . - "'$pay_total' " . - ")"); - } - - // Post a payment, SQL-Ledger style. - // - function slPostPayment($trans_id, $thispay, $thisdate, $thissrc, $code, $thisins, $debug) { - global $chart_id_cash, $chart_id_ar; - if ($GLOBALS['oer_config']['ws_accounting']['enabled'] === 2) - die("Internal error calling slPostPayment()"); - // Post a payment: add to ar, subtract from cash. - slAddTransaction($trans_id, $chart_id_ar , $thispay , $thisdate, $thissrc, $code, $thisins, $debug); - slAddTransaction($trans_id, $chart_id_cash, 0 - $thispay, $thisdate, $thissrc, $code, $thisins, $debug); - slUpdateAR($trans_id, 0, $thispay, $thisdate, $debug); - } - //writing the check details to Session Table on ERA proxcessing -function arPostSession($payer_id,$check_number,$check_date,$pay_total,$post_to_date,$deposit_date,$debug) { - $query = "INSERT INTO ar_session( " . - "payer_id,user_id,closed,reference,check_date,pay_total,post_to_date,deposit_date,patient_id,payment_type,adjustment_code,payment_method " . - ") VALUES ( " . - "'$payer_id'," . - $_SESSION['authUserID']."," . - "0," . - "'ePay - $check_number'," . - "'$check_date', " . - "$pay_total, " . - "'$post_to_date','$deposit_date', " . - "0,'insurance','insurance_payment','electronic'" . - ")"; - if ($debug) { - echo $query . "
\n"; - } else { - $sessionId=sqlInsert($query); - return $sessionId; - } - } - - // Post a payment, new style. - // - function arPostPayment($patient_id, $encounter_id, $session_id, $amount, $code, $payer_type, $memo, $debug, $time='', $codetype='') { - $codeonly = $code; - $modifier = ''; - $tmp = strpos($code, ':'); - if ($tmp) { - $codeonly = substr($code, 0, $tmp); - $modifier = substr($code, $tmp+1); - } - if (empty($time)) $time = date('Y-m-d H:i:s'); - $query = "INSERT INTO ar_activity ( " . - "pid, encounter, code_type, code, modifier, payer_type, post_time, post_user, " . - "session_id, memo, pay_amount " . - ") VALUES ( " . - "'$patient_id', " . - "'$encounter_id', " . - "'$codetype', " . - "'$codeonly', " . - "'$modifier', " . - "'$payer_type', " . - "'$time', " . - "'" . $_SESSION['authUserID'] . "', " . - "'$session_id', " . - "'$memo', " . - "'$amount' " . - ")"; - sqlStatement($query); - return; - } - - // Post a charge. This is called only from sl_eob_process.php where - // automated remittance processing can create a new service item. - // Here we add it as an unauthorized item to the billing table. - // - function arPostCharge($patient_id, $encounter_id, $session_id, $amount, $units, $thisdate, $code, $description, $debug, $codetype='') { - /***************************************************************** - // Select an existing billing item as a template. - $row= sqlQuery("SELECT * FROM billing WHERE " . - "pid = '$patient_id' AND encounter = '$encounter_id' AND " . - "code_type = 'CPT4' AND activity = 1 " . - "ORDER BY id DESC LIMIT 1"); - $this_authorized = 0; - $this_provider = 0; - if (!empty($row)) { - $this_authorized = $row['authorized']; - $this_provider = $row['provider_id']; - } - *****************************************************************/ - - if (empty($codetype)) { - // default to CPT4 if empty, which is consistent with previous functionality. - $codetype="CPT4"; - } - $codeonly = $code; - $modifier = ''; - $tmp = strpos($code, ':'); - if ($tmp) { - $codeonly = substr($code, 0, $tmp); - $modifier = substr($code, $tmp+1); - } - - addBilling($encounter_id, - $codetype, - $codeonly, - $description, - $patient_id, - 0, - 0, - $modifier, - $units, - $amount, - '', - ''); - } - - // See comments above. - // In the SQL-Ledger case this service item is added only to SL and - // not to the billing table. - // - function slPostCharge($trans_id, $thisamt, $thisunits, $thisdate, $code, $thisins, $description, $debug) { - global $chart_id_income, $chart_id_ar; - if ($GLOBALS['oer_config']['ws_accounting']['enabled'] === 2) - die("Internal error calling slPostCharge()"); - // Post an adjustment: add negative invoice item, add to ar, subtract from income - slAddLineItem($trans_id, $code, $thisamt, $thisunits, $thisins, $description, $debug); - if ($thisamt) { - slAddTransaction($trans_id, $chart_id_ar , 0 - $thisamt, $thisdate, $description, $code, $thisins, $debug); - slAddTransaction($trans_id, $chart_id_income, $thisamt , $thisdate, $description, $code, $thisins, $debug); - slUpdateAR($trans_id, $thisamt, 0, '', $debug); - } - } - - // Post an adjustment, SQL-Ledger style. - // - function slPostAdjustment($trans_id, $thisadj, $thisdate, $thissrc, $code, $thisins, $reason, $debug) { - global $chart_id_income, $chart_id_ar; - if ($GLOBALS['oer_config']['ws_accounting']['enabled'] === 2) - die("Internal error calling slPostAdjustment()"); - // Post an adjustment: add negative invoice item, add to ar, subtract from income - $adjdate = fixDate($thisdate); - $description = "Adjustment $adjdate $reason"; - slAddLineItem($trans_id, $code, 0 - $thisadj, 1, $thisins, $description, $debug); - if ($thisadj) { - slAddTransaction($trans_id, $chart_id_ar, $thisadj, $thisdate, "InvAdj $thissrc", $code, $thisins, $debug); - slAddTransaction($trans_id, $chart_id_income, 0 - $thisadj, $thisdate, "InvAdj $thissrc", $code, $thisins, $debug); - slUpdateAR($trans_id, 0 - $thisadj, 0, '', $debug); - } - } - - // Post an adjustment, new style. - // - function arPostAdjustment($patient_id, $encounter_id, $session_id, $amount, $code, $payer_type, $reason, $debug, $time='', $codetype='') { - $codeonly = $code; - $modifier = ''; - $tmp = strpos($code, ':'); - if ($tmp) { - $codeonly = substr($code, 0, $tmp); - $modifier = substr($code, $tmp+1); - } - if (empty($time)) $time = date('Y-m-d H:i:s'); - $query = "INSERT INTO ar_activity ( " . - "pid, encounter, code_type, code, modifier, payer_type, post_user, post_time, " . - "session_id, memo, adj_amount " . - ") VALUES ( " . - "'$patient_id', " . - "'$encounter_id', " . - "'$codetype', " . - "'$codeonly', " . - "'$modifier', " . - "'$payer_type', " . - "'" . $_SESSION['authUserID'] . "', " . - "'$time', " . - "'$session_id', " . - "'$reason', " . - "'$amount' " . - ")"; - sqlStatement($query); - return; - } - - function arGetPayerID($patient_id, $date_of_service, $payer_type) { - if ($payer_type < 1 || $payer_type > 3) return 0; - $tmp = array(1 => 'primary', 2 => 'secondary', 3 => 'tertiary'); - $value = $tmp[$payer_type]; - $query = "SELECT provider FROM insurance_data WHERE " . - "pid = ? AND type = ? AND date <= ? " . - "ORDER BY date DESC LIMIT 1"; - $nprow = sqlQuery($query, array($patient_id,$value,$date_of_service) ); - if (empty($nprow)) return 0; - return $nprow['provider']; - } - - // Make this invoice re-billable, new style. - // - function arSetupSecondary($patient_id, $encounter_id, $debug,$crossover=0) { - if ($crossover==1) { - //if claim forwarded setting a new status - $status=6; - - } else { - - $status=1; - - } - // Determine the next insurance level to be billed. - $ferow = sqlQuery("SELECT date, last_level_billed " . - "FROM form_encounter WHERE " . - "pid = '$patient_id' AND encounter = '$encounter_id'"); - $date_of_service = substr($ferow['date'], 0, 10); - $new_payer_type = 0 + $ferow['last_level_billed']; - if ($new_payer_type < 3 && !empty($ferow['last_level_billed']) || $new_payer_type == 0) - ++$new_payer_type; - - $new_payer_id = arGetPayerID($patient_id, $date_of_service, $new_payer_type); - - if ($new_payer_id) { - // Queue up the claim. - if (!$debug) - updateClaim(true, $patient_id, $encounter_id, $new_payer_id, $new_payer_type,$status, 5, '', 'hcfa','',$crossover); - } - else { - // Just reopen the claim. - if (!$debug) - updateClaim(true, $patient_id, $encounter_id, -1, -1, $status, 0, '','','',$crossover); - } - - return xl("Encounter ") . $encounter . xl(" is ready for re-billing."); - } - - // Make this invoice re-billable, SQL-Ledger style. - // - function slSetupSecondary($invid, $debug) { - global $sl_err, $GLOBALS, $code_types; - - if ($GLOBALS['oer_config']['ws_accounting']['enabled'] === 2) - die("Internal error calling slSetupSecondary()"); - - $info_msg = ''; - - // Get some needed items from the SQL-Ledger invoice. - $arres = SLQuery("select invnumber, transdate, customer_id, employee_id, " . - "shipvia from ar where ar.id = $invid"); - if ($sl_err) die($sl_err); - $arrow = SLGetRow($arres, 0); - if (! $arrow) die(xl('There is no match for invoice id') . ' = ' . "$trans_id."); - $customer_id = $arrow['customer_id']; - $date_of_service = $arrow['transdate']; - list($trash, $encounter) = explode(".", $arrow['invnumber']); - - // Get the OpenEMR PID corresponding to the customer. - $pdrow = sqlQuery("SELECT patient_data.pid " . - "FROM integration_mapping, patient_data WHERE " . - "integration_mapping.foreign_id = $customer_id AND " . - "integration_mapping.foreign_table = 'customer' AND " . - "patient_data.id = integration_mapping.local_id"); - $pid = $pdrow['pid']; - if (! $pid) die(xl("Cannot find patient from SQL-Ledger customer id") . " = $customer_id."); - - // Determine the ID of the next insurance company (if any) to be billed. - $new_payer_id = -1; - $new_payer_type = -1; - $insdone = strtolower($arrow['shipvia']); - foreach (array('ins1' => 'primary', 'ins2' => 'secondary', 'ins3' => 'tertiary') as $key => $value) { - if (strpos($insdone, $key) === false) { - $nprow = sqlQuery("SELECT provider FROM insurance_data WHERE " . - "pid = '$pid' AND type = '$value' AND date <= '$date_of_service' " . - "ORDER BY date DESC LIMIT 1"); - if (!empty($nprow['provider'])) { - $new_payer_id = $nprow['provider']; - $new_payer_type = substr($key, 3); - } - break; - } - } - - // Find out if the encounter exists. - $ferow = sqlQuery("SELECT pid FROM form_encounter WHERE " . - "encounter = $encounter"); - $encounter_pid = $ferow['pid']; - - // If it exists, just update the billing items. - if ($encounter_pid) { - if ($encounter_pid != $pid) - die(xl("Expected form_encounter.pid to be ") . $pid . ', ' . xl(' but was ') . $encounter_pid); - - // If there's a payer ID queue it up, otherwise just reopen it. - if ($new_payer_id > 0) { - // TBD: implement a default bill_process and target in config.php, - // it should not really be hard-coded here. - if (!$debug) - updateClaim(true, $pid, $encounter, $new_payer_id, $new_payer_type, 1, 5, '', 'hcfa'); - } else { - if (!$debug) - updateClaim(true, $pid, $encounter, -1, -1, 1, 0, ''); - } - - $info_msg = xl("Encounter ") . $encounter . xl(" is ready for re-billing."); - return; - } - - // If we get here then the encounter does not already exist. This should - // only happen if A/R was converted from an earlier system. In this case - // the encounter ID should be the date of service, and we will create the - // encounter. - - // If it does not exist then it better be (or start with) a date. - if (! preg_match("/^20\d\d\d\d\d\d/", $encounter)) - die(xl("Internal error: encounter '") . $encounter . xl("' should exist but does not.")); - - $employee_id = $arrow['employee_id']; - - // Get the OpenEMR provider info corresponding to the SQL-Ledger salesman. - $drrow = sqlQuery("SELECT users.id, users.username, users.facility_id " . - "FROM integration_mapping, users WHERE " . - "integration_mapping.foreign_id = $employee_id AND " . - "integration_mapping.foreign_table = 'salesman' AND " . - "users.id = integration_mapping.local_id"); - $provider_id = $drrow['id']; - if (! $provider_id) die(xl("Cannot find provider from SQL-Ledger employee = ") . $employee_id ); - - if (! $date_of_service) die(xl("Invoice has no date!")); - - // Generate a new encounter number. - $conn = $GLOBALS['adodb']['db']; - $new_encounter = $conn->GenID("sequences"); - - // Create the "new encounter". - $encounter_id = 0; - $query = "INSERT INTO form_encounter ( " . - "date, reason, facility_id, pid, encounter, onset_date, provider_id " . - ") VALUES ( " . - "'$date_of_service', " . - "'" . xl('Imported from Accounting') . "', " . - "'" . addslashes($drrow['facility_id']) . "', " . - "$pid, " . - "$new_encounter, " . - "'$date_of_service', " . - "'$provider_id' " . - ")"; - if ($debug) { - echo $query . "
\n"; - echo xl("Call to addForm() goes here.
") . "\n"; - } else { - $encounter_id = idSqlStatement($query); - if (! $encounter_id) die(xl("Insert failed: ") . $query); - addForm($new_encounter, xl("New Patient Encounter"), $encounter_id, - "newpatient", $pid, 1, $date_of_service); - $info_msg = xl("Encounter ") . $new_encounter . xl(" has been created. "); - } - - // For each invoice line item with a billing code we will insert - // a billing row with payer_id set to -1. Order the line items - // chronologically so that each procedure code will be followed by - // its associated icd9 code. - - $inres = SLQuery("SELECT * FROM invoice WHERE trans_id = $invid " . - "ORDER BY id"); - if ($sl_err) die($sl_err); - - // When nonzero, this will be the ID of a billing row that needs to - // have its justify field set. - $proc_ins_id = 0; - - for ($irow = 0; $irow < SLRowCount($inres); ++$irow) { - $row = SLGetRow($inres, $irow); - $amount = sprintf('%01.2f', $row['sellprice'] * $row['qty']); - - // Extract the billing code. - $code = xl("Unknown"); - if (preg_match("/([A-Za-z0-9]\d\d\S*)/", $row['serialnumber'], $matches)) { - $code = strtoupper($matches[1]); - } - else if (preg_match("/([A-Za-z0-9]\d\d\S*)/", $row['description'], $matches)) { - $code = strtoupper($matches[1]); - } - - list($code, $modifier) = explode("-", $code); - - // Set the billing code type and description. - $code_type = ""; - $code_text = ""; - - foreach ($code_types as $key => $value) { - if (preg_match("/$key/", $row['serialnumber'])) { - $code_type = $key; - if (!$value['diag']) { - $code_text = xl("Procedure") . " $code"; - } else { - $code_text = xl("Diagnosis") . " $code"; - if ($proc_ins_id) { - $query = "UPDATE billing SET justify = '$code' WHERE id = $proc_ins_id"; - if ($debug) { - echo $query . "
\n"; - } else { - sqlQuery($query); - } - $proc_ins_id = 0; - } - } - break; - } - } - - // Skip adjustments. - if (! $code_type) continue; - - // Insert the billing item. If this for a procedure code then save - // the row ID so that we can update the "justify" field with the ICD9 - // code, which should come next in the loop. - // - $query = "INSERT INTO billing ( " . - "date, code_type, code, pid, provider_id, user, groupname, authorized, " . - "encounter, code_text, activity, payer_id, billed, bill_process, " . - "bill_date, modifier, units, fee, justify, target " . - ") VALUES ( " . - "NOW(), " . - "'$code_type', " . - "'$code', " . - "$pid, " . - "0, " . // was $provider_id but that is now in form_encounter - "'" . $_SESSION['authId'] . "', " . - "'" . $_SESSION['authProvider'] . "', " . - "1, " . - "$new_encounter, " . - "'$code_text', " . - "1, " . - "$new_payer_id, " . - ($new_payer_id > 0 ? "1, " : "0, ") . - ($new_payer_id > 0 ? "5, " : "0, ") . - ($new_payer_id > 0 ? "NOW(), " : "NULL, ") . - "'$modifier', " . - "0, " . - "$amount, " . - "'', " . - ($new_payer_id > 0 ? "'hcfa' " : "NULL ") . - ")"; - if ($debug) { - echo $query . "
\n"; - } else { - $proc_ins_id = idSqlStatement($query); - if ($code_types[$code_type]['diag']) - $proc_ins_id = 0; - } - } - - // Finally, change this invoice number to contain the new encounter number. - // - $new_invnumber = "$pid.$new_encounter"; - $query = "UPDATE ar SET invnumber = '$new_invnumber' WHERE id = $invid"; - if ($debug) { - echo $query . "
\n"; - } else { - SLQuery($query); - if ($sl_err) die($sl_err); - $info_msg .= xl("This invoice number has been changed to ") . $new_invnumber; - } - - return $info_msg; - } -?> + + // + // This program is free software; you can redistribute it and/or + // modify it under the terms of the GNU General Public License + // as published by the Free Software Foundation; either version 2 + // of the License, or (at your option) any later version. + + include_once("patient.inc"); + include_once("billing.inc"); + include_once("invoice_summary.inc.php"); + + $chart_id_cash = 0; + $chart_id_ar = 0; + $chart_id_income = 0; + $services_id = 0; + + + // Try to figure out our invoice number (pid.encounter) from the + // claim ID and other stuff in the ERA. This should be straightforward + // except that some payers mangle the claim ID that we give them. + // + function slInvoiceNumber(&$out) { + $invnumber = $out['our_claim_id']; + $atmp = preg_split('/[ -]/', $invnumber); + $acount = count($atmp); + + $pid = 0; + $encounter = 0; + if ($acount == 2) { + $pid = $atmp[0]; + $encounter = $atmp[1]; + } + else if ($acount == 3) { + $pid = $atmp[0]; + $brow = sqlQuery("SELECT encounter FROM billing WHERE " . + "pid = '$pid' AND encounter = '" . $atmp[1] . "' AND activity = 1"); + + $encounter = $brow['encounter']; + } + else if ($acount == 1) { + $pres = sqlStatement("SELECT pid FROM patient_data WHERE " . + "lname LIKE '" . addslashes($out['patient_lname']) . "' AND " . + "fname LIKE '" . addslashes($out['patient_fname']) . "' " . + "ORDER BY pid DESC"); + while ($prow = sqlFetchArray($pres)) { + if (strpos($invnumber, $prow['pid']) === 0) { + $pid = $prow['pid']; + $encounter = substr($invnumber, strlen($pid)); + break; + } + } + } + + if ($pid && $encounter) $invnumber = "$pid.$encounter"; + return array($pid, $encounter, $invnumber); + } + + // This gets a posting session ID. If the payer ID is not 0 and a matching + // session already exists, then its ID is returned. Otherwise a new session + // is created. + // + function arGetSession($payer_id, $reference, $check_date, $deposit_date='', $pay_total=0) { + if (empty($deposit_date)) $deposit_date = $check_date; + if ($payer_id) { + $row = sqlQuery("SELECT session_id FROM ar_session WHERE " . + "payer_id = '$payer_id' AND reference = '$reference' AND " . + "check_date = '$check_date' AND deposit_date = '$deposit_date' " . + "ORDER BY session_id DESC LIMIT 1"); + if (!empty($row['session_id'])) return $row['session_id']; + } + return sqlInsert("INSERT INTO ar_session ( " . + "payer_id, user_id, reference, check_date, deposit_date, pay_total " . + ") VALUES ( " . + "'$payer_id', " . + "'" . $_SESSION['authUserID'] . "', " . + "'$reference', " . + "'$check_date', " . + "'$deposit_date', " . + "'$pay_total' " . + ")"); + } + //writing the check details to Session Table on ERA proxcessing +function arPostSession($payer_id,$check_number,$check_date,$pay_total,$post_to_date,$deposit_date,$debug) { + $query = "INSERT INTO ar_session( " . + "payer_id,user_id,closed,reference,check_date,pay_total,post_to_date,deposit_date,patient_id,payment_type,adjustment_code,payment_method " . + ") VALUES ( " . + "'$payer_id'," . + $_SESSION['authUserID']."," . + "0," . + "'ePay - $check_number'," . + "'$check_date', " . + "$pay_total, " . + "'$post_to_date','$deposit_date', " . + "0,'insurance','insurance_payment','electronic'" . + ")"; + if ($debug) { + echo $query . "
\n"; + } else { + $sessionId=sqlInsert($query); + return $sessionId; + } + } + + // Post a payment, new style. + // + function arPostPayment($patient_id, $encounter_id, $session_id, $amount, $code, $payer_type, $memo, $debug, $time='', $codetype='') { + $codeonly = $code; + $modifier = ''; + $tmp = strpos($code, ':'); + if ($tmp) { + $codeonly = substr($code, 0, $tmp); + $modifier = substr($code, $tmp+1); + } + if (empty($time)) $time = date('Y-m-d H:i:s'); + $query = "INSERT INTO ar_activity ( " . + "pid, encounter, code_type, code, modifier, payer_type, post_time, post_user, " . + "session_id, memo, pay_amount " . + ") VALUES ( " . + "'$patient_id', " . + "'$encounter_id', " . + "'$codetype', " . + "'$codeonly', " . + "'$modifier', " . + "'$payer_type', " . + "'$time', " . + "'" . $_SESSION['authUserID'] . "', " . + "'$session_id', " . + "'$memo', " . + "'$amount' " . + ")"; + sqlStatement($query); + return; + } + + // Post a charge. This is called only from sl_eob_process.php where + // automated remittance processing can create a new service item. + // Here we add it as an unauthorized item to the billing table. + // + function arPostCharge($patient_id, $encounter_id, $session_id, $amount, $units, $thisdate, $code, $description, $debug, $codetype='') { + /***************************************************************** + // Select an existing billing item as a template. + $row= sqlQuery("SELECT * FROM billing WHERE " . + "pid = '$patient_id' AND encounter = '$encounter_id' AND " . + "code_type = 'CPT4' AND activity = 1 " . + "ORDER BY id DESC LIMIT 1"); + $this_authorized = 0; + $this_provider = 0; + if (!empty($row)) { + $this_authorized = $row['authorized']; + $this_provider = $row['provider_id']; + } + *****************************************************************/ + + if (empty($codetype)) { + // default to CPT4 if empty, which is consistent with previous functionality. + $codetype="CPT4"; + } + $codeonly = $code; + $modifier = ''; + $tmp = strpos($code, ':'); + if ($tmp) { + $codeonly = substr($code, 0, $tmp); + $modifier = substr($code, $tmp+1); + } + + addBilling($encounter_id, + $codetype, + $codeonly, + $description, + $patient_id, + 0, + 0, + $modifier, + $units, + $amount, + '', + ''); + } + + // Post an adjustment, new style. + // + function arPostAdjustment($patient_id, $encounter_id, $session_id, $amount, $code, $payer_type, $reason, $debug, $time='', $codetype='') { + $codeonly = $code; + $modifier = ''; + $tmp = strpos($code, ':'); + if ($tmp) { + $codeonly = substr($code, 0, $tmp); + $modifier = substr($code, $tmp+1); + } + if (empty($time)) $time = date('Y-m-d H:i:s'); + $query = "INSERT INTO ar_activity ( " . + "pid, encounter, code_type, code, modifier, payer_type, post_user, post_time, " . + "session_id, memo, adj_amount " . + ") VALUES ( " . + "'$patient_id', " . + "'$encounter_id', " . + "'$codetype', " . + "'$codeonly', " . + "'$modifier', " . + "'$payer_type', " . + "'" . $_SESSION['authUserID'] . "', " . + "'$time', " . + "'$session_id', " . + "'$reason', " . + "'$amount' " . + ")"; + sqlStatement($query); + return; + } + + function arGetPayerID($patient_id, $date_of_service, $payer_type) { + if ($payer_type < 1 || $payer_type > 3) return 0; + $tmp = array(1 => 'primary', 2 => 'secondary', 3 => 'tertiary'); + $value = $tmp[$payer_type]; + $query = "SELECT provider FROM insurance_data WHERE " . + "pid = ? AND type = ? AND date <= ? " . + "ORDER BY date DESC LIMIT 1"; + $nprow = sqlQuery($query, array($patient_id,$value,$date_of_service) ); + if (empty($nprow)) return 0; + return $nprow['provider']; + } + + // Make this invoice re-billable, new style. + // + function arSetupSecondary($patient_id, $encounter_id, $debug,$crossover=0) { + if ($crossover==1) { + //if claim forwarded setting a new status + $status=6; + + } else { + + $status=1; + + } + // Determine the next insurance level to be billed. + $ferow = sqlQuery("SELECT date, last_level_billed " . + "FROM form_encounter WHERE " . + "pid = '$patient_id' AND encounter = '$encounter_id'"); + $date_of_service = substr($ferow['date'], 0, 10); + $new_payer_type = 0 + $ferow['last_level_billed']; + if ($new_payer_type < 3 && !empty($ferow['last_level_billed']) || $new_payer_type == 0) + ++$new_payer_type; + + $new_payer_id = arGetPayerID($patient_id, $date_of_service, $new_payer_type); + + if ($new_payer_id) { + // Queue up the claim. + if (!$debug) + updateClaim(true, $patient_id, $encounter_id, $new_payer_id, $new_payer_type,$status, 5, '', 'hcfa','',$crossover); + } + else { + // Just reopen the claim. + if (!$debug) + updateClaim(true, $patient_id, $encounter_id, -1, -1, $status, 0, '','','',$crossover); + } + + return xl("Encounter ") . $encounter . xl(" is ready for re-billing."); + } +?> diff --git a/library/sql-ledger.inc b/library/sql-ledger.inc deleted file mode 100644 index f94e09e34..000000000 --- a/library/sql-ledger.inc +++ /dev/null @@ -1,53 +0,0 @@ - 0) { - $tmp = pg_fetch_array($res, 0); - return $tmp[0]; - } - return ""; -} - -function SLFreeResult($res) { - pg_freeresult($res); -} -?> diff --git a/sl_convert.php b/sl_convert.php deleted file mode 100644 index 69ea6e85d..000000000 --- a/sl_convert.php +++ /dev/null @@ -1,345 +0,0 @@ - -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This may be run after an upgraded OpenEMR has been installed. -// Its purpose is to extract A/R information from SQL-Ledger and -// convert it to the OpenEMR tables that maintain A/R internally, -// thus eliminating SQL-Ledger. - -// Significant changes were made around November 2009: SQL-Ledger -// data is now considered authoritative, and the billing table is -// modified to reflect that. This is so that financial reports in -// the new system will (hopefully) match up with the old system. -// Discrepancies are logged to the display during conversion. - -// Disable PHP timeout. This will not work in safe mode. -ini_set('max_execution_time', '0'); - -$ignoreAuth=true; // no login required - -require_once('interface/globals.php'); -require_once('library/sql-ledger.inc'); -require_once('library/invoice_summary.inc.php'); -require_once('library/sl_eob.inc.php'); - -// Set this to true to skip all database changes. -$dry_run = false; - -if (!$dry_run) { - $tmp = sqlQuery("SELECT count(*) AS count FROM ar_activity"); - if ($tmp['count']) die("ar_activity and ar_session must be empty to run this script!"); -} -?> - - -OpenEMR Conversion from SQL-Ledger - - - -OpenEMR Conversion from SQL-Ledger -

- -Be patient, this will take a while...

"; -flush(); - -// This marker will eventually tell us which encounters have no -// matching invoice. -if (!$dry_run) { - sqlStatement("UPDATE form_encounter SET last_level_billed = -1"); -} - -$invoice_count = 0; -$activity_count = 0; - -$res = SLQuery("SELECT id, invnumber, transdate, shipvia, intnotes " . - "FROM ar WHERE invnumber LIKE '%.%' ORDER BY id"); - -for ($irow = 0; $irow < SLRowCount($res); ++$irow) { - $row = SLGetRow($res, $irow); - list($pid, $encounter) = explode(".", $row['invnumber']); - - $tmp = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " . - "pid = '$pid' AND encounter = '$encounter'"); - if ($tmp['count'] == 0) { - echo "SQL-Ledger invoice $pid.$encounter has no matching encounter " . - "and is ignored. This will affect financial reports!
\n"; - continue; - } - - $billing = array(); - $provider_id = 0; - $last_biller = 0; - $svcdate = $row['transdate']; - - if (!$dry_run) { - // Delete any TAX rows from billing for encounters in SQL-Ledger. - sqlStatement("UPDATE billing SET activity = 0 WHERE " . - "pid = '$pid' AND encounter = '$encounter' AND " . - "code_type = 'TAX'"); - } - - // Get all billing table items with money for this encounter, and - // compute provider ID and billing status. - $bres = sqlStatement("SELECT * FROM billing WHERE " . - "pid = '$pid' AND encounter = '$encounter' AND activity = 1 " . - "AND code_type != 'TAX' AND fee != 0 ORDER BY fee DESC"); - while ($brow = sqlFetchArray($bres)) { - if (!$provider_id) $provider_id = $brow['provider_id']; - if (!$last_biller && $brow['billed'] && !empty($brow['payer_id'])) - $last_biller = $brow['payer_id']; - $billing[$brow['id']] = $brow; - } - - // Get invoice details. - $invlines = get_invoice_summary($row['id'], true); - // print_r($invlines); // debugging - ksort($invlines); - - // For each line item or payment from the invoice... - foreach ($invlines as $codekey => $codeinfo) { - ksort($codeinfo['dtl']); - $code = strtoupper($codekey); - if ($code == 'CO-PAY' || $code == 'UNKNOWN') $code = ''; - - $is_product = substr($code, 0, 5) == 'PROD:'; - - $codeonly = $code; - $modifier = ''; - $tmp = explode(":", $code); - if (!empty($tmp[1])) { - $codeonly = $tmp[0]; - $modifier = $tmp[1]; - } - - foreach ($codeinfo['dtl'] as $dtlkey => $dtlinfo) { - $dtldate = trim(substr($dtlkey, 0, 10)); - - if (empty($dtldate)) { // if this is a charge - $charge = $dtlinfo['chg']; - - // Zero charges don't matter. - if ($charge == 0) continue; - - // Insert taxes but ignore other charges. - if ($code == 'TAX') { - if (!$dry_run) { - sqlInsert("INSERT INTO billing ( date, encounter, code_type, code, code_text, " . - "pid, authorized, user, groupname, activity, billed, provider_id, " . - "modifier, units, fee, ndc_info, justify ) values ( " . - "'$svcdate 00:00:00', '$encounter', 'TAX', 'TAX', '" . - addslashes($dtlinfo['dsc']) . "', " . - "'$pid', '1', '$provider_id', 'Default', 1, 1, 0, '', '1', " . - "'$charge', '', '' )"); - } - } - else { - // Non-tax charges for products are in the drug_sales table. - // We won't bother trying to make sure they match the invoice. - if ($is_product) continue; - - // Look up this charge in the $billing array. - // If found, remove it from the array and skip to the next detail item. - // Otherwise add it to the billing table and log the discrepancy. - $posskey = 0; - foreach ($billing as $key => $brow) { - $bcode = strtoupper($brow['code']); - $bcodeonly = $bcode; - if ($brow['modifier']) $bcode .= ':' . strtoupper($brow['modifier']); - if ($bcode === $code && $brow['fee'] == $charge) { - unset($billing[$key]); - continue 2; // done with this detail item - } - else if (($bcodeonly === $codeonly || (empty($codeonly) && $charge != 0)) && $brow['fee'] == $charge) { - $posskey = $key; - } - } - if ($posskey) { - // There was no exact match, but there was a match if the modifiers - // are ignored or if the SL code is empty. Good enough. - unset($billing[$posskey]); - continue; - } - // This charge is not in the billing table! - $codetype = preg_match('/^[A-V]/', $code) ? 'HCPCS' : 'CPT4'; - // Note that get_invoice_summary() loses the code type. The above - // statement works for normal U.S. clinics, but sites that have - // charges other than CPT4 and HCPCS will need to have their code - // types for these generated entries, if any, fixed. - if (!$dry_run) { - sqlInsert("INSERT INTO billing ( date, encounter, code_type, code, code_text, " . - "pid, authorized, user, groupname, activity, billed, provider_id, " . - "modifier, units, fee, ndc_info, justify ) values ( " . - "'$svcdate 00:00:00', '$encounter', '$codetype', '$codeonly', - 'Copied from SQL-Ledger by sl_convert.php', " . - "'$pid', '1', '$provider_id', 'Default', 1, 1, 0, '$modifier', '1', " . - "'$charge', '', '' )"); - } - echo "Billing code '$code' with charge \$$charge was copied from " . - "SQL-Ledger invoice $pid.$encounter.
\n"; - flush(); - } // end non-tax charge - - // End charge item logic. Continue to the next invoice detail item. - continue; - - } // end if charge - - $payer_id = empty($dtlinfo['ins']) ? 0 : $dtlinfo['ins']; - $session_id = 0; - - // Compute a reasonable "source" value. For payments this will - // commonly be a check number, for adjustments we have none. - $source = empty($dtlinfo['src']) ? '' : $dtlinfo['src']; - $source = preg_replace('!^Ins[123]/!i', '', $source); - $source = preg_replace('!^Pt/!i', '', $source); - if ($source == '' && empty($dtlinfo['pmt'])) { - $source = 'From SQL-Ledger'; - } - - // For insurance payers look up or create the session table entry. - if ($payer_id) { - if (!$dry_run) { - $session_id = arGetSession($payer_id, addslashes($source), $dtldate); - } - } - // For non-insurance payers deal with copay duplication. - else if ($code == '') { - if (!empty($dtlinfo['pmt'])) { - // Skip payments that are already present in the billing table as copays. - foreach ($billing as $key => $brow) { - if ($brow['code_type'] == 'COPAY' && (0 - $brow['fee']) == $dtlinfo['pmt']) { - unset($billing[$key]); - continue 2; // done with this detail item - } - } - } // end if payment - } // end not insurance - - $payer_type = 0; - - if (!empty($dtlinfo['pmt'])) { // it's a payment - $tmp = strtolower($dtlinfo['src']); - for ($i = 1; $i <= 3; ++$i) { - if (strpos($tmp, "ins$i") !== false) $payer_type = $i; - } - if (!$dry_run) { - arPostPayment($pid, $encounter, $session_id, $dtlinfo['pmt'], $code, - $payer_type, addslashes($source), 0, "$dtldate 00:00:00"); - if ($session_id) { - sqlStatement("UPDATE ar_session SET pay_total = pay_total + '" . - $dtlinfo['pmt'] . "' WHERE session_id = '$session_id'"); - } - } - } - else { // it's an adjustment - $tmp = strtolower($dtlinfo['rsn']); - for ($i = 1; $i <= 3; ++$i) { - if (strpos($tmp, "ins$i") !== false) $payer_type = $i; - } - if (!$dry_run) { - arPostAdjustment($pid, $encounter, $session_id, 0 - $dtlinfo['chg'], - $code, $payer_type, addslashes($dtlinfo['rsn']), 0, "$dtldate 00:00:00"); - } - } - - ++$activity_count; - } // end detail item - } // end code - - // Compute last insurance level billed. - $last_level_billed = 0; - if ($last_biller) { - $invdate = $row['transdate']; - $tmp = sqlQuery("SELECT type FROM insurance_data WHERE " . - "pid = '$pid' AND provider = '$last_biller' AND " . - "date <= '$invdate' ORDER BY date DESC, id ASC LIMIT 1"); - $last_level_billed = ($tmp['type'] == 'tertiary') ? - 3 : (($tmp['type'] == 'secondary') ? 2 : 1); - } - - // Compute last insurance level closed. - $last_level_closed = 0; - $tmp = strtolower($row['shipvia']); - for ($i = 1; $i <= 3; ++$i) { - if (strpos($tmp, "ins$i") !== false) $last_level_closed = $i; - } - - // Compute last statement date and number of statements sent. - $last_stmt_date = "NULL"; - $stmt_count = 0; - $i = 0; - $tmp = strtolower($row['intnotes']); - while (($i = strpos($tmp, 'statement sent ', $i)) !== false) { - $i += 15; - $last_stmt_date = "'" . substr($tmp, $i, 10) . "'"; - ++$stmt_count; - } - - if (!$dry_run) { - sqlStatement("UPDATE form_encounter SET " . - "last_level_billed = '$last_level_billed', " . - "last_level_closed = '$last_level_closed', " . - "last_stmt_date = $last_stmt_date, " . - "stmt_count = '$stmt_count' " . - "WHERE pid = '$pid' AND encounter = '$encounter'"); - } - - // Delete and show a warning for any unmatched copays or charges. - foreach ($billing as $key => $brow) { - if (!$dry_run) { - sqlStatement("UPDATE billing SET activity = 0 WHERE id = '$key'"); - } - if ($brow['code_type'] == 'COPAY') { - echo "Patient payment of \$" . sprintf('%01.2f', 0 - $brow['fee']); - } - else { - echo "Charge item '" . $brow['code'] . "' with amount \$" . - sprintf('%01.2f', $brow['fee']); - } - echo " was not found in SQL-Ledger invoice $pid.$encounter " . - "and has been removed from the encounter.
\n"; - flush(); - } - - ++$invoice_count; -} // end invoice -SLClose(); - -if (!$dry_run) { - $feres = sqlStatement("SELECT * FROM form_encounter WHERE " . - "last_level_billed = -1 ORDER BY pid, encounter"); - while ($ferow = sqlFetchArray($feres)) { - $pid = 0 + $ferow['pid']; - $encounter = 0 + $ferow['encounter']; - $tmp = sqlQuery("SELECT sum(fee) AS sum FROM billing WHERE " . - "pid = '$pid' AND encounter = '$encounter' AND " . - "activity = 1 AND billed = 1"); - if ($tmp['sum'] != 0) { - $sum = sprintf('%0.2f', 0 + $tmp['sum']); - arPostAdjustment($pid, $encounter, 0, $sum, - '', 0, 'Missing SL invoice', 0, date('Y-m-d') . ' 00:00:00'); - echo "Adjustment amount $sum was applied to write off billed " . - "items in encounter $pid.$encounter because it has no matching " . - "invoice.
\n"; - } - sqlStatement("UPDATE form_encounter SET last_level_billed = 0 " . - "WHERE id = '" . $ferow['id'] . "'"); - } -} - -echo "
\n"; -echo "$invoice_count SQL-Ledger invoices were processed.
\n"; -echo "$activity_count payments and adjustments were posted.
\n"; -?> - - - - -- 2.11.4.GIT