Appointment Count by Patient Category and Appointment Type

We need a report that provides total number of a particular type of appointment by pt category for a specified period.

Be sure to adjust the date range in the WHERE clause for your desired period.

This query uses the GROUP BY ROLLUP (  ) statement to give grand and subtotals as well as the results for each specific patient category, provider type, and service code combination. Wherever you see NULL in the result set, interpret as “ALL”.

SELECT
  COALESCE(d.categcode,'None') AS "PtCategory",
  COALESCE(f.ApptType,'None') AS "ApptType",
  COUNT(distinct a.detailnum) AS ApptCount
FROM
  sos.appt_d a
  JOIN sos.patients c ON a.ptnum = c.ptnum
  LEFT OUTER JOIN sos.ptcategs d ON c.ptcategnum = d.ptcategnum 
  LEFT OUTER JOIN sos.appttypes f ON a.appttypenum = f.appttypenum
WHERE 
  a.adate BETWEEN '2012-01-01' AND '2012-12-31'
  AND c.licnum = 101
GROUP BY ROLLUP ("PtCategory","ApptType")

Service Count and Units By Patient Category, Provider Type, and Service Code

We need a report that provides units provided/charges for a specified patient category, broken down by provider type and service code for a specified date range from both active and inactive clients in dataset 101.

Be sure to adjust the date range in the WHERE clause for your desired period.

This query uses the GROUP BY ROLLUP (  ) statement to give grand and subtotals as well as the results for each specific patient category, provider type, and service code combination. Wherever you see NULL in the result set, interpret as “ALL”.

SELECT
  COALESCE(d.categcode,'None') AS "PtCategory",
  COALESCE(f.provtypecode,'None') AS "ProvType",
  g.srvcode AS "ServiceCode",
  COUNT(distinct b.jnum) AS ServiceCount,
  SUM(b.units) AS TotalUnits
FROM
  sos.journal a
  JOIN sos.jcharges b ON a.jnum = b.jnum
  JOIN sos.patients c ON a.ptnum = c.ptnum
  LEFT OUTER JOIN sos.ptcategs d ON c.ptcategnum = d.ptcategnum
  JOIN sos.providers e ON b.providernum = e.providernum
  JOIN sos.services g ON b.servicenum = g.servicenum
  LEFT OUTER JOIN sos.provtype f ON e.provtypenum = f.provtypenum
WHERE
  a.trandate BETWEEN '2012-01-01' AND '2012-12-31'
  AND a.amount > 0
  AND c.licnum = 101
GROUP BY ROLLUP ("PtCategory","ProvType","ServiceCode")

Count of Intakes for Past 365 Days With Specified Dx

We need the total number of new (the past 365 days) intakes that were given a primary or secondary diagnosis of 304.4, including sub-diagnoses. In addition to the grand total, we also would like a breakdown by provider.

The following query demonstrates some simple date arithmetic in the WHERE clause to provide a dynamic calculation of the date 365 days ago. In addition, we are using the GROUP BY ROLLUP ( … ) structure to get both the grand total and the subtotals in the same result set. When you run the query you will see a top row where NULL appears in the provider and provcode columns. In this context, whereever you see NULL, it actually should be interpreted as “all”. The first row then shows the number of intakes for “all providers” and “all provcodes,” in other words, the grand total.

SELECT
  UPPER(provlname) + ', ' + provfname AS "Provider",provcode, COUNT(DISTINCT pt.ptnum) as "N"
FROM
  sos.patients pt
  JOIN sos.ptcsu csu ON pt.ptnum = csu.ptnum
  JOIN sos.ptcsudx ptdx ON csu.ptcsunum = ptdx.ptcsunum
  JOIN sos.providers prv ON pt.providernum = prv.providernum
WHERE
  (pt.intakedate >= (TODAY()-365))
  AND (dxcode1 LIKE '304.4%' OR dxcode2 LIKE '304.4%')
GROUP BY
  ROLLUP ("Provider",provcode)

Balance Breakdown By Patient On Specified Date

 Our auditors have requested a report of outstanding balances per client, as of Dec 31, 2011, separated by liability (Medicare, Medicaid, private insurance and self-pay). Insurance type is specified by “Coverage Type” on the Additional tab of the Insurance Carrie/Plan. We want to report patients in either the Active or Inactive lists, as long as they have a balance of some kind at the end of 2011.

Because we are looking for balances on a previous date, we have to tally up all the charges and payments on or before that date, then subtract the latter from the former to find the balance. To do that will require a bunch of embedded subqueries as you can see in the query below. If you want to run the query for a different date, be sure to replace ALL the instances of ‘2011-12-31’!

The output specified in this example will go to an HTML format file called AUDIT2011.HTML located in the C:\SOS folder. You can output the results to screen for inspection before outputting to file by inserting two dashes or slashes at the beginning of the last line. Just remove those characters when you are ready to generate the file. The benefit of outputting in HTML format is that you can view the results in a web browser, or open the file with Excel for additional massaging.

SELECT
   a.lastname, a.firstname, a.id AS "Account ID",
   -- Medicare
   COALESCE((SELECT SUM(chgsplamt) 
   FROM sos.jchgsplits chs JOIN sos.ptpayors ptp ON chs.ptpayornum = ptp.ptpayornum JOIN sos.carriers car ON ptp.payornum = car.payornum
   WHERE chs.ptnum = a.ptnum AND car.coverage = 'C' AND chs.chgspldate <= '2011-12-31'),0) AS "Medicare Charges",
   COALESCE((SELECT SUM(crsplamt) 
   FROM sos.jcrsplits crs 
     JOIN sos.jchgsplits chs ON crs.chgsplnum = chs.chgsplnum 
     JOIN sos.ptpayors ptp ON chs.ptpayornum = ptp.ptpayornum 
     JOIN sos.carriers car ON ptp.payornum = car.payornum 
     JOIN sos.jcredits cre ON crs.jnum = cre.jnum 
     JOIN sos.journal jou ON cre.jnum = jou.jnum
   WHERE chs.ptnum = a.ptnum 
     AND car.coverage = 'C' 
     AND chs.chgspldate <= '2011-12-31' 
     AND jou.trandate <= '2011-12-31') ,0) AS "Medicare Credits",
   ("Medicare Charges" - "Medicare Credits") AS "Medicare Balance",
  -- Medicaid
   COALESCE((SELECT SUM(chgsplamt) 
   FROM sos.jchgsplits chs JOIN sos.ptpayors ptp ON chs.ptpayornum = ptp.ptpayornum JOIN sos.carriers car ON ptp.payornum = car.payornum
   WHERE chs.ptnum = a.ptnum AND car.coverage = 'D' AND chs.chgspldate <= '2011-12-31'),0) AS "Medicaid Charges",
   COALESCE((SELECT SUM(crsplamt) 
   FROM sos.jcrsplits crs 
     JOIN sos.jchgsplits chs ON crs.chgsplnum = chs.chgsplnum 
     JOIN sos.ptpayors ptp ON chs.ptpayornum = ptp.ptpayornum 
     JOIN sos.carriers car ON ptp.payornum = car.payornum 
     JOIN sos.jcredits cre ON crs.jnum = cre.jnum 
     JOIN sos.journal jou ON cre.jnum = jou.jnum
   WHERE chs.ptnum = a.ptnum 
     AND car.coverage = 'D' 
     AND chs.chgspldate <= '2011-12-31' 
     AND jou.trandate <= '2011-12-31' ) ,0) AS "Medicaid Credits",
   ("Medicaid Charges" - "Medicaid Credits") AS "Medicaid Balance",
   -- Private Ins 
   COALESCE((SELECT SUM(chgsplamt) 
   FROM sos.jchgsplits chs JOIN sos.ptpayors ptp ON chs.ptpayornum = ptp.ptpayornum JOIN sos.carriers car ON ptp.payornum = car.payornum
   WHERE chs.ptnum = a.ptnum AND car.coverage NOT IN ('C','D') AND chs.chgspldate <= '2011-12-31'),0) AS "Private Ins Charges",
   COALESCE((SELECT SUM(crsplamt) 
   FROM sos.jcrsplits crs 
     JOIN sos.jchgsplits chs ON crs.chgsplnum = chs.chgsplnum 
     JOIN sos.ptpayors ptp ON chs.ptpayornum = ptp.ptpayornum 
     JOIN sos.carriers car ON ptp.payornum = car.payornum 
     JOIN sos.jcredits cre ON crs.jnum = cre.jnum 
     JOIN sos.journal jou ON cre.jnum = jou.jnum
   WHERE chs.ptnum = a.ptnum 
     AND car.coverage NOT IN ('C','D') 
     AND chs.chgspldate <= '2011-12-31' 
     AND jou.trandate <= '2011-12-31' ) ,0) AS "Private Ins Credits",
   ("Private Ins Charges" - "Private Ins Credits") AS "Private Ins Balance",
   -- Self-Pay
   COALESCE((SELECT SUM(chgsplamt) 
   FROM sos.jchgsplits chs JOIN sos.ptpayors ptp ON chs.ptpayornum = ptp.ptpayornum JOIN sos.payors pay ON ptp.payornum = pay.payornum
   WHERE chs.ptnum = a.ptnum AND pay.payortype IN ('P','O') AND chs.chgspldate <= '2011-12-31'),0) AS "Self-Pay Charges",
   COALESCE((SELECT SUM(crsplamt) 
   FROM sos.jcrsplits crs 
     JOIN sos.jchgsplits chs ON crs.chgsplnum = chs.chgsplnum 
     JOIN sos.ptpayors ptp ON chs.ptpayornum = ptp.ptpayornum 
     JOIN sos.payors pay ON ptp.payornum = pay.payornum
     JOIN sos.jcredits cre ON crs.jnum = cre.jnum 
     JOIN sos.journal jou ON cre.jnum = jou.jnum
   WHERE chs.ptnum = a.ptnum 
     AND pay.payortype IN ('P','O') 
     AND chs.chgspldate <= '2011-12-31' 
     AND jou.trandate <= '2011-12-31' ) ,0) AS "Self-Pay Credits",
   ("Self-Pay Charges" - "Self-Pay Credits") AS "Self-Pay Balance"

FROM 
  sos.patients a  
WHERE
  "Medicare Balance" <> 0
  OR "Medicaid Balance" <> 0
  OR "Private Ins Balance" <> 0
  OR "Self-Pay Balance" <> 0
ORDER BY
  a.lastname, a.firstname, a.id

 

Insurance Carriers with Active Patients

In order to clean up my list of insurance carriers in SOS I would like to list all active Insurance Carrier’s/ Plans (defined as insurances with Patients tied to them) with their Address, Phone number, and NEIC Numbers. Actually I would like this list with just the count of active patient accounts, and a second list that includes the patients linked to each carrier.

This request is a little vague in that it is not clear whether the linked patients should be restricted to active patients or not. The first query assumes that it is only carriers linked to active patients (in the Active Patient List and without a discharge date), but you can just remove the flag and dischargedate conditions in the WHERE clause to get carriers linked to any patient.

SELECT
  c.payorname AS "Ins Plan",
  COUNT(a.ptnum) AS "ActivePatientCount",
  c.PayorNum,
  d.companynum AS "NEIC#",
  c.Addr1,
  c.Addr2,
  c.City,
  c.State,
  c.Zip,
  c.Phone1Desc,
  (c.phone1area+'-'+phone1) AS "Phone1",
  c.Phone2Desc,
  (c.phone2area+'-'+phone2) AS "Phone2",
  c.Phone3Desc,
  (c.phone3area+'-'+phone3) AS "Phone3"
FROM
  sos.patients a
  JOIN sos.ptpayors b ON a.ptnum = b.ptnum
  JOIN sos.payors c ON b.payornum = c.payornum
  JOIN sos.carriers d ON c.payornum = d.payornum
WHERE
  a.flag = 0
  AND a.dischargedate IS NULL
  AND c.payortype = 'I'
GROUP BY
  "Ins Plan",c.payornum,"NEIC#",c.Addr1, c.Addr2, c.City, c.State, c.Zip,c.Phone1Desc,"Phone1",c.Phone2Desc,"Phone2",c.Phone3Desc,"Phone3"
HAVING
  "ActivePatientCount" > 0
ORDER BY
  c.payorname, c.payornum

The second query removes the COUNT function, the GROUP BY and HAVING clauses, and adds the patient names and ID’s.

SELECT
  c.payorname AS "Ins Plan",
  c.PayorNum,
  (UPPER(a.lastname)+', '+a.firstname+' / '+a.id) AS "Patient Name/ID",
  d.companynum AS "NEIC#",
  c.Addr1 AS "InsAddr1",
  c.Addr2 AS "InsAddr2",
  c.City AS "InsCity",
  c.State AS "InsState",
  c.Zip AS "InsZip",
  c.Phone1Desc AS "InsPhone1Desc",
  (c.phone1area+'-'+phone1) AS "Phone1",
  c.Phone2Desc AS "InsPhone2Desc",
  (c.phone2area+'-'+phone2) AS "Phone2",
  c.Phone3Desc AS "InsPhone3Desc",
  (c.phone3area+'-'+phone3) AS "Phone3"
FROM
  sos.patients a
  JOIN sos.ptpayors b ON a.ptnum = b.ptnum
  JOIN sos.payors c ON b.payornum = c.payornum
  JOIN sos.carriers d ON c.payornum = d.payornum
WHERE
  a.flag = 0
  AND a.dischargedate IS NULL
  AND c.payortype = 'I'
ORDER BY
  c.payorname, c.payornum