Detailed List of Charge Balances by Payor On Specified Date

We have an audit coming up and would like to have a detailed listing, down to the charge split level, of unpaid charges on the last day of our fiscal year. It would be most helpful to have the list sorted by payor and date.

In the following query, you must replace the date in two places with the last date of your fiscal period. Remember that this is a listing of charge splits, so there can be several lines for the same service item, even for a single payor. The sort order keeps splits for the same payor and service together.

SELECT
  //patient
  a.licnum AS "DataSet",
  a.id AS "AccountID",
  a.lastname AS "LastName",
  a.firstname AS "FirstName",
  //service
  a.jnum AS "TransactionNum",
  a.trandate AS "SrvDate",
  a.provcode AS "ProvCode",
  a.srvcode AS "SrvCode",
  a.amount AS "TotalFee",
  a.balance AS "TotalBalance",
  //payor
  TRIM(c.payorname + ' ' +c.firstname) AS "Payor",
  a.chgsplamt AS "AmtChargedPayor",
  (SELECT COALESCE(SUM(crsplamt),0)
       FROM sos.jcrsplits
       WHERE chgsplnum = a.chgsplnum AND dateapplied <= '2008-09-30') AS "PayorCreditsApplied",
  (a.chgsplamt - "PayorCreditsApplied") AS "PayorBalance",
  //billing dates
  COALESCE(STRING(a.firstbilled),'') AS "DateFirstBilled",
  COALESCE(STRING(a.lastbilled),'') AS "DateMostRecentlyBilled"
FROM
  sos.rv_charges a
  JOIN sos.ptpayors b ON a.ptpayornum = b.ptpayornum
  JOIN sos.payors c ON b.payornum = c.payornum
WHERE
   "AmtChargedPayor" <> 0
  AND "PayorBalance" <> 0
  AND  (a.paiddate IS NULL OR a.paiddate > '2008-09-30')
ORDER BY
  "Payor","SrvDate","TransactionNum"
The following version combines splits if a single payor has more than one split on the same service charge entry.
SELECT
  //patient
  a.licnum AS "DataSet",
  a.id AS "AccountID",
  a.lastname AS "LastName",
  a.firstname AS "FirstName",
  //service
  a.jnum AS "TransactionNum",
  a.trandate AS "SrvDate",
  a.provcode AS "ProvCode",
  a.srvcode AS "SrvCode",
  a.amount AS "TotalFee",
  a.balance AS "TotalBalance",
  //payor
  TRIM(c.payorname + ' ' +c.firstname) AS "Payor",
  SUM(a.chgsplamt) AS "AmtChargedPayor",
  SUM((SELECT COALESCE(SUM(crsplamt),0)
          FROM sos.jcrsplits
          WHERE chgsplnum = a.chgsplnum AND dateapplied <= '2008-09-30')) AS "PayorCreditsApplied",
  ("AmtChargedPayor" - "PayorCreditsApplied") AS "PayorBalance",
  //billing dates
  MIN(COALESCE(STRING(a.firstbilled),'')) AS "DateFirstBilled",
  MAX(COALESCE(STRING(a.lastbilled),'')) AS "DateMostRecentlyBilled"
FROM
  sos.rv_charges a
  JOIN sos.ptpayors b ON a.ptpayornum = b.ptpayornum
  JOIN sos.payors c ON b.payornum = c.payornum
WHERE
  (a.paiddate IS NULL OR a.paiddate > '2008-09-30')
GROUP BY
  "DataSet","Payor","Lastname","Firstname","ID","SrvDate","ProvCode",
  "SrvCode","TotalFee","TotalBalance","TransactionNum"
HAVING
  "AmtChargedPayor" <> 0
  AND "PayorBalance" <> 0
ORDER BY
  "DataSet","Payor","SrvDate","TransactionNum"

	

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.