Patients Seen In Period With Insurance And Provider

Is there a query that will list all clients that were seen in a certain time frame along with name of insurance for a specific provider?

Adjust the desired date range and provider code in the WHERE clause below.

SELECT DISTINCT
  a.lastname,
  a.firstname,
  a.id,
  a.provcode,
  (IF c.payortype = 'I' THEN c.payorname ELSE '' ENDIF) AS "Insurance"
FROM
  sos.rv_charges a
  JOIN sos.ptpayors b ON a.ptpayornum = b.ptpayornum
  JOIN sos.payors c ON b.payornum = c.payornum
WHERE
  trandate BETWEEN '2002-01-01' AND '2002-01-31'
  AND a.provcode = '3'
ORDER BY
  a.lastname, a.firstname, a.id

Patients By Rendering Provider

I need a report that lists by rendering provider the names of any patients who had a service by that provider—and I need to set the date parameters and choose the therapist I want that info on.

Here’s the query, which is easy enough. Just adjust the conditions in the WHERE clause
for the desired date range and provider codes.

SELECT
  DISTINCT pr.provcode, pt.lastname, pt.firstname, pt.id
FROM
  sos.providers pr
  JOIN sos.jcharges jc ON pr.providernum = jc.providernum
  JOIN sos.journal jou ON jc.jnum = jou.jnum
  JOIN sos.patients pt ON jou.ptnum = pt.ptnum
WHERE
  jou.trandate BETWEEN '2010-01-01' AND '2010-12-31'
  AND pr.provcode IN ('VB1','VB2','VB3')
ORDER BY
  pr.provcode, pt.lastname, pt.firstname, pt.id

Patients by Provider and Category

I would like to run a report that shows patients by provider & category.

At first glance this is a very basic, multi-table query, but some patients might not have an assigned primary provider and/or category. In those situations, it would be better to output something other than “NULL” or blank space. The following query shows two ways of doing that.

In addition, rather than doing columns for every data element, we can create provider and patient columns that have the full name information in a single column.

The WHERE clause filters out discharged and inactive list patients. The order of the results can be manipulated by changing the element order in the ORDER BY clause.

SELECT
  IF a.providernum IS NULL
     THEN 'No Primary Provider'
     ELSE (b.provlname+', ' + b.provfname + ' (' + b.provcode + ')')
  ENDIF AS "Provider",
  COALESCE(c.categdesc,'No Category') AS "Category",
 (a.lastname+', ' + a.firstname + ' / ' + a.id) AS "Patient"
FROM
  sos.patients a
  LEFT OUTER JOIN sos.providers b ON a.providernum = b.providernum
  LEFT OUTER JOIN sos.ptcategs c ON a.ptcategnum = c.ptcategnum
WHERE
  a.flag = 0
  AND a.dischargedate IS NULL
ORDER BY "Provider","Category","Patient"

Patient Visits By Provider

Does anyone out there have a query we can use to get data regarding the number of visits a client makes to a provider? We would like to follow how often people come to see our providers. I imagine the query would track by provider, by client, intake date, and subsequent treatment visits.

Take a look at the following, relatively complex query, which delivers the average number of non-zero$ service entries for each provider, plus the itemized list of patients seen by the provider, with the number of services rendered for each patient. The WHERE clauses allow you to specify the selection is for when the patient’s intake date or first non-zero service falls with a specified date range. You must specify the date range in TWO places, and the provider codes to analyze in TWO places. The reason is that there are two queries that are UNIONed into a single result set. One does the details and the other does the average. They won’t match up unless the conditions are set identically for both. This guy also uses DATE, TODAY, and COALESCE functions and the MIN and COUNT aggregate functions, plus an embedded, correlated subquery to determine the date of the first service for each patient. It is definitely not a place to start if you wanted to learn basic SQL, but it has lots of interesting features if you are ready to try your hand at more advanced stuff.

Anyway, you don’t have to understand it to use it! Just paste it into your DBISQL utility, modify the selection criteria, and let ‘er rip.

Note that there is a conceptual gotcha. By including patients who are still in treatment, your results may be invalid. Let’s say that you have a new provider who has only been seeing patients for two months. Assuming weekly visits, her average visits per patient will come up as 8 or fewer. The results are going to be skewed by the number of patients who are still being seen.

I think it is more meaningful to only include patients who have been discharged, so that you are looking at a completed episode of care for each patient. To do so, you would add:

AND (p.flag = 0 OR p.dischargedate IS NOT NULL)

to the two WHERE clauses. That will include only patients in the Inactive list or who have a date in the Discharge Date field. I have done that below, but the lines won’t execute unless you remove the two slashes at the beginning of the additional condition in the WHERE clause of both of the main queries.

SELECT
  v.provcode,
  p.lastname,p.firstname,p.id,
  DATE(COALESCE(intakedate,(SELECT MIN(trandate)
                            FROM sos.journal
                            WHERE ptnum = p.ptnum
                            AND trantype='S' AND amount > 0)
       ,'1900-01-01')) AS "Initial",
  COUNT(DISTINCT j.jnum) AS "Visits"
FROM
  sos.patients p
  JOIN sos.journal j ON p.ptnum = j.ptnum
  JOIN sos.jcharges c ON j.jnum = c.jnum
  JOIN sos.providers v ON c.providernum = v.providernum
WHERE
  "Initial" BETWEEN '1995-01-01' AND TODAY()
  AND v.provcode IN ('A','B','C')
  //AND (p.flag = 0 OR p.dischargedate IS NOT NULL)
GROUP BY
  v.provcode,p.lastname,p.firstname,p.id,"Initial"
UNION
SELECT
  v.provcode,
  '--AVERAGE','NUMBER OF','VISITS',
   NULL,
  COUNT(DISTINCT j.jnum)/COUNT(DISTINCT j.ptnum) AS "Avg Vists"
FROM
  sos.patients p
  JOIN sos.journal j ON p.ptnum = j.ptnum
  JOIN sos.jcharges c ON j.jnum = c.jnum
  JOIN sos.providers v ON c.providernum = v.providernum
WHERE
  DATE(COALESCE(intakedate,(SELECT MIN(trandate)
                            FROM sos.journal
                            WHERE ptnum = p.ptnum
                            AND trantype='S'
                            AND amount > 0)
       ,'1900-01-01')) BETWEEN '1995-01-01' AND TODAY()
  AND v.provcode IN ('A','B','C')
  //AND (p.flag = 0 OR p.dischargedate IS NOT NULL)
GROUP BY
  v.provcode
ORDER BY
  1,2,3,4

Service Count By Provider, Patient Category and Service Code For Period

I need total # of patients seen, broken down by provider, patient category, and service code, for a specific time frame.

SELECT
(a.provfname + ' '+a.provlname) AS "Provider",
c.categcode AS "Category",
a.srvcode AS "Service",
COUNT(DISTINCT a.ptnum) AS "Pt Count"
FROM
sos.rv_charges a
JOIN sos.patients b ON a.ptnum = b.ptnum
LEFT OUTER JOIN sos.ptcategs c ON b.ptcategnum = c.ptcategnum
WHERE
a.trandate BETWEEN '1980-01-01' AND '2008-12-31'
GROUP BY
"Provider","Category","Service"