CHIP Patients List

We have a state-funded Children’s Health Insurance Program (CHIP) that is offered via a number of commercial insurers.  Like all states, the public money is quickly drying up, so insurers are using third parties to scour their records to find those patients for whom
“erroneous” payments were made.  Aetna is using a company called Aftermath to do this with CHIP patients, but it has been a disaster as the company is making what appears to be serious false assumptions.

We need to identify those CHIP clients under any insurer so that we can check benefits before every visit.

The only way to identify these clients is to have a query that identifies patients younger than 19 who have insurance policies in which they are also the subscriber. The list should include only patients who have received services in the last 120 days.

SELECT DISTINCT
  a.lastname,a.firstname,a.id
FROM
  sos.patients a
  JOIN sos.rv_policies b ON a.ptnum = b.ptnum
  JOIN sos.journal c ON a.ptnum = c.ptnum
WHERE
  sos.AgeInYears(a.dob,today()) < 19
  AND reltoinsd = '01'
  AND c.trantype = 'S'
  AND c.trandate BETWEEN (TODAY() - 120) AND TODAY()
ORDER BY a.lastname,a.firstname,a.id

 

 

Birthdays and Ages

 How do I calculate current ages? I am trying to create a list of active patients 18 and younger with their ages and birthdays.

You might think that you could use the standard SQL function called DATEDIFF to just subtract the years, but that won’t give you an accurate age if the current date is earlier in the year than the birthday. To get a true age calculation, use the custom function “AGEINYEARS” that SOS has added to your database. It takes two parameters, the date of birth and the reference date on which you want to calculate age. Most of the time that will be CURRENT DATE, but you can use a different date if desired.

SELECT
  lastname  AS "Last Name",
  firstname AS "First Name",
  id,
  sos.AGEINYEARS(dob,CURRENT DATE) AS "Current Age" ,
  DATEFORMAT (dob, 'MM-DD-YYYY') AS "Date of Birth"
FROM
  sos.patients
WHERE
  flag = 0  /* active patients only */
  AND dischargedate IS NULL    /* no discharge date has been entered */
  AND "Current Age" <= 18  /* only patients younger than 18 years of age */
ORDER BY 
  lastname,firstname, id

 

Billing Addresses For Mail Merge

The following query will create an Excel file suitable for Mail Merge use. The results will have information from the “Bill To” tab of patient information, if present, otherwise will use the patient information. It does not pull information from alternate payors on the
account. The file generated is in HTML format, but you can open it in Excel and re-save as an Excel format file.

SELECT
  TRIM(IF a.billtofirstname > '' THEN a.billtofirstname ELSE a.firstname ENDIF) AS "FirstName",
  TRIM(IF a.billtolastname > '' THEN a.billtolastname ELSE a.lastname ENDIF) AS "LastName",
  TRIM("firstname" + ' ' + "lastname") AS "FullName",
  TRIM(IF a.billtoaddr1 > '' THEN a.billtoaddr1 ELSE b.Addr1 ENDIF) AS "AddressLine1",
  TRIM(IF a.billtoaddr2 > '' THEN a.billtoaddr2 ELSE b.Addr2 ENDIF) AS "AddressLine2",
  TRIM(IF a.billtocity > '' THEN a.billtocity ELSE b.City ENDIF) AS "City",
  TRIM(IF a.billtostate > '' THEN a.billtostate ELSE b.State ENDIF) AS "State",
  TRIM(IF a.billtozip > '' THEN a.billtozip ELSE b.Zip ENDIF) AS "Zip"
FROM
  sos.patients a JOIN sos.payors b ON a.payornum = b.payornum
WHERE
  a.flag = 0    /* only patients in active list */
  AND a.licnum = 101    /*only patients in the main data set*/
;
OUTPUT TO c:\sos\billingaddresses.html FORMAT HTML

Let’s say that you just want addresses for patients who have been seen for billable services in the past two years (730 days). There is a column in the ptvars view called “lfeedate” that has the date of the last billable service. So we can add ptvars to the FROM clause, and the lfeedate to the WHERE clause, as shown below:

SELECT
  TRIM(IF a.billtofirstname > '' THEN a.billtofirstname ELSE a.firstname ENDIF) AS "FirstName",
  TRIM(IF a.billtolastname > '' THEN a.billtolastname ELSE a.lastname ENDIF) AS "LastName",
  TRIM("firstname" + ' ' + "lastname") AS "FullName",
  TRIM(IF a.billtoaddr1 > '' THEN a.billtoaddr1 ELSE b.Addr1 ENDIF) AS "AddressLine1",
  TRIM(IF a.billtoaddr2 > '' THEN a.billtoaddr2 ELSE b.Addr2 ENDIF) AS "AddressLine2",
  TRIM(IF a.billtocity > '' THEN a.billtocity ELSE b.City ENDIF) AS "City",
  TRIM(IF a.billtostate > '' THEN a.billtostate ELSE b.State ENDIF) AS "State",
  TRIM(IF a.billtozip > '' THEN a.billtozip ELSE b.Zip ENDIF) AS "Zip"
FROM
  sos.patients a
  JOIN sos.payors b ON a.payornum = b.payornum
  JOIN sos.ptvars c ON a.ptnum = c.ptnum
WHERE
  a.flag = 0    /* only patients in active list */
  AND a.licnum = 101    /*only patients in the main data set*/
 AND c.lfeedate > (CURRENT DATE - 730) /* service within past two years */
;
OUTPUT TO c:\sos\billingaddresses.html FORMAT HTML

 

Aging Grouped By Insurance Carrier

I am looking for an aging report that displays just the insurance payor aging, grouped by carrier. That is, a report that has Insurance Carrier as a group heading with the relevant patient aging within the group.

If you want to export to Excel, you must use DBISQLG. The older DBISQLC version, on the other hand, has a handy TEXT output format that is lacking in the G version. These are Sybase tools and I am at a loss as to why they omitted certain features in the new version. They are written in different programming languages (C vs. Java), so perhaps that explains it.

You could also use FlySpeed SQL Query, which has a feature to export nicely formatted results to PDF or Excel.

SELECT DISTINCT
  a.payorname AS "INS PAYOR",
  (b.lastname +', '+ b.firstname +' / '+ b.ID) AS "Patient",
  SUM(a.balance) AS "BALANCE",
  SUM(a.age0to30) AS "Current",
  SUM(a.age61to90) AS "31 - 60",
  SUM(a.age91to120) AS "91-120",
  SUM(a.ageovr120) AS "OVER 120",
  SUM(a.ageunapplied ) AS "Unapplied",
  COALESCE((SELECT STRING(MAX(lastbilled))
    FROM sos.jchgsplits
    WHERE ptpayornum = a.ptpayornum AND lastbilled IS NOT NULL),'NONE')
    AS "Last Billed"
FROM
  sos.rv_ptpayors a JOIN sos.patients b
WHERE
  a.payortype = 'I'
  AND a.balance > 0
GROUP BY
  "INS PAYOR","Patient",a.ptpayornum

UNION   /* --- COMBINE RESULT SETS OF QUERY ABOVE WITH QUERY BELOW */

SELECT
  a.payorname AS "INS PAYOR",
  'SUBTOTAL',
  SUM(a.balance) AS "BALANCE",
  SUM(a.age0to30) AS "Current",
  SUM(a.age61to90) AS "31 - 60",
  SUM(a.age91to120) AS "91-120",
  SUM(a.ageovr120) AS "OVER 120",
  SUM(a.ageunapplied ) AS "Unapplied",
  ' ' AS "Last Billed"
FROM
  sos.rv_ptpayors a
WHERE
  a.payortype = 'I'
  AND a.balance > 0
GROUP BY
  "INS PAYOR"

UNION  /* --- COMBINE RESULT SETS OF QUERY ABOVE WITH QUERY BELOW - */

SELECT
  'Z-Z-Z--- GRAND TOTALS ---Z-Z-Z',
  ' ',
  SUM(a.balance) AS "BALANCE",
  SUM(a.age0to30) AS "Current",
  SUM(a.age61to90) AS "31 - 60",
  SUM(a.age91to120) AS "91-120",
  SUM(a.ageovr120) AS "OVER 120",
  SUM(a.ageunapplied ) AS "Unapplied",
  ' ' AS "Last Billed"
FROM
  sos.rv_ptpayors a
WHERE
  a.payortype = 'I'
  AND a.balance > 0

/*---- Sort combined result sets by first, then second column ------- */
ORDER BY
  1,2

This query uses additional queries to get subtotals and grand total, then uses the UNION operator to combine the result sets.

Adjustments by Type and by Client for a Period

I want a detailed or summary report of adjustments for a particular date range, grouped by type and then by client.

 

The detailed query would be:

SELECT
    adjcode, fullnameid, trandate, payorname, amount
FROM
    sos.rv_credits
WHERE
    credtype = 'Adjustment'
    AND trandate BETWEEN '2000-01-01' AND '2008-07-31'
ORDER BY
    adjcode, fullnameid, trandate

 

and the summary query would be:

SELECT
    adjcode, fullnameid, payorname, SUM(amount)
FROM
    sos.rv_credits
WHERE
    credtype = 'Adjustment'
    AND trandate BETWEEN '2000-01-01' AND '2008-07-31'
GROUP BY
    adjcode, fullnameid, payorname
ORDER BY
    adjcode, fullnameid, payorname