Referring Physicians for Payors with ID’s and Patient Count

I'm writing a query and want to print out medicare and bcbs numbers in addition to default id for referral
sources. I can get the defaultid from refsrcs but the other numbers come up as null. I upgraded to the
latest version of OM and it now looks like there is a different system for entering specific insurance
numbers for referral sources so I was wondering if this is a factor? Also is there a way to get a count for
the number of patients a particular referring physician has sent our way?
OK, looks like you just want referral sources associated with active patients based on intake date. Couple
of things you need to consider...

Firstly, the referring physicians used on claims may not match the referral source stored in Patients. The
latter could be "yellow pages", former patients, or whatever, while the former should be only physicians
or other healthcare providers. Given that you are interested in the ID's, it seems that you are probably
more interested in the referring physician that prints on the claim forms. That is in the claim setup table
(PtCSU) not in Patients. To get to those, you would have to add a JOIN to PtCSU. In addition you will
have to (left outer) join refpayorids and payors:
SELECT
 trim(refname + ', ' + b.firstname) as "RefName",
 b.address1,
 b.address2,
 b.city,
 b.zip,
 b.phone,
 b. Defaultid,
 e.payorname,
 d.providerid,
 d.secondaryid,
 COUNT(distinct a.ptnum) AS "PtCount"
FROM
 sos.patients A
 JOIN sos.ptcsu c ON c.ptnum = a.ptnum
 JOIN sos.refsrcs b ON b.refsrcnum = c.refsrcnum
 LEFT OUTER JOIN sos.refpayorids d ON b.refsrcnum = d.refsrcnum
 LEFT OUTER JOIN sos.payors e ON e.payornum = d.payornum
WHERE
 a.flag=0
 AND a.intakedate > '1980-10-01'
 AND a.licnum='101'
 AND e.payornum IN (101,102)
GROUP BY
 refname,
 b.address1,
 b.address2,
 b.city,
 b.zip,b.phone,
 b.defaultid,
 e.payorname,
 d.providerid,
 d.secondaryid
ORDER BY
 refname
;OUTPUT TO c:\sos\refinfo.html FORMAT HTML

	

Number of Services for Patients by Service Code and Rendering Provider

Here is the information I need:
Clients name: (using the Intake as of Sept. 2003)
Providers name:
Number of times in Individual sessions (CPT 90806 Code: IP)
Number of times in Group (CPT 90853 Code: Grp)
Is that possible to get the clients name and the number of sessions they have been in for individual and
group sessions?

I took a little liberty with your request to show the number of sessions of all rendered services, but this
can be trimmed down, if you like. You did not indicate whether the provider was the rendering or primary.
I used rendering, so you will see the number of sessions for each provider for each patient (if there are
multiple providers rendering services to a single patient). The output of the query will go to a
Lotus-format file called sessioncount.wks in the C:\SOS folder. Excel will open this file without complaint.

If you want to change the file name or location, modify the last line of the query. (Note that you can
un-comment line 15 if you want to restrict the results to just the IP and GRP service codes. I would
suggest running the more inclusive query first in case the providers are using different codes than you
expect.)

Note that we use JOIN rather than LEFT OUTER JOIN to link the tables in this case. No data will be
omitted because all these values and rows must be present for every charge entry. You can’t have a
charge without a patient (ptnum), provider (providernum), or service (servicenum).

SELECT
   (UPPER(a.LastName)+', '+a.FirstName+' / '+a.id) as "Client",
   c.ProvCode as "Rendering_Provider",
   d.CPTCode,
   d.srvcode,
   COUNT(*) as "NumSessions"
FROM
   sos.patients a
   JOIN sos.jcharges b on a.ptnum = b.ptnum
   JOIN sos.providers c on b.providernum=c.providernum
   JOIN sos.services d on b.servicenum=d.servicenum
WHERE
   a.intakedate > '2003-08-31'
   AND a.flag = 0
   // AND d.srvcode IN ('IP','GRP')
   // remove the beginning slashes on line above to return only those service codes
GROUP BY
   client,
   rendering_provider,
   cptcode,
   srvcode
ORDER BY
   client,
   rendering_provider,
   cptcode,
   srvcode
;OUTPUT TO c:\sos\sessioncount.html FORMAT HTML

Patients by Last Four Digits of Social Security Number

Recently we had an audit done by an outside agency that used the last 4 digits of the SS# to identify the
patient charges they chose to audit. We have a need to take a look at several of those charts, but the
only identifying data we now have is the last 4 SS# digits. How can I retrieve the patients with just this
information?
The following query should provide you with what you need. Just replace 1234 in the last line with the
digits you want to search. Don't neglect the single quotes around the number:
SELECT
   lastname, 
   firstname, 
   id, 
   socsec
FROM
   sos.patients
WHERE
   RIGHT(socsec,4) = '1234'
If you have a list of numbers you would like to do in a single shot, you can modify it as follows:
SELECT
   lastname, 
   firstname, 
   id, 
   socsec, 
   RIGHT(socsec,4) as "last4"
FROM
   sos.patients
WHERE
   last4 IN ('1234','5678','2468','4321')
or, for a complete list of patients, sorted by the last four digits:
SELECT
   RIGHT(socsec,4) as "last4", 
   lastname, 
   firstname, 
   id, 
   socsec
FROM
   sos.patients
ORDER BY 
   last4

List Patients Based on True Date of First Service

A user complained that he could not use the intake date recorded in the system because it did not reflect
the true date of first service. (The intake date will default to the current system date when initializing a
new patient account unless you enter a date manually.)

The following query selects accounts based on the date of the earliest transaction date found in the
patient ledger. It will output the accounts that had their first service entry during the date range specified:
SELECT
   Lastname + ', '+ Firstname +' / '+ id AS "Account",
   MIN(trandate) AS "Intake"
FROM
   sos.Journal a 
   JOIN sos.Patients b ON a.ptnum = b.ptnum
WHERE
   a.trantype = 'S'
GROUP BY
   account
HAVING
   Intake BETWEEN '2005-04-01' AND '2005-04-30'
Note the use of the aggregate function MIN, along with the GROUP BY to determine the earliest service
date for each patient. The condition “a.trantype = ‘S’” restricts the transactions to just charge entries. The
query also uses correlation names to alias the name and id expression (aliased as “account”), the
MIN(trandate) expression as “intake”, and the tables (aliased as “a” and “b”).

Also note that we have conditions in both a WHERE clause and a HAVING clause. Conditions that
examine the results of aggregate expressions must be placed in a HAVING clause following the GROUP
BY. The rule of thumb here is that you can put your condition in the WHERE if it is looking at values that
exist in the original rows of the table, but if you want to restrict output based on values that don’t exist
until the data is grouped, then you must put the condition in the HAVING clause.
In this case, the trantype value is present in the journal table, so that condition goes in the WHERE. On
the other hand, the minimum date can’t be determined until we have grouped the rows in journal by
patient account. We therefore stick our “intake” (MIN(trandate)) condition in the HAVING, after the
GROUPED BY.

Mailing Labels for Patients with Specific Insurance Payors

We need to send letters to all of our psychiatrists' patients catagorized by insurance payor. How can I
get mailing labels for these letters? The scenario is that our docs have removed themselves from the
Magellan and United Behavioral Health panels and will only accept fee-for-services from those patients.
Obviouly we need to inform the patients - several times and in several ways. The first step is to identify
them and prepare labels for the letters to be sent.

OK, so we can identify the patients using the primary provider code. Good. Let's start with this query. I'll
include the payorname in the output so you can check the export. You can ignore that column when you
read the data into Word to create your labels.
SELECT
   (a.firstname + ' '+a.lastname) as "name",
   a.addr1 as "addr1",
   a.addr2 as "addr2",
   (a.city+', '+a.state+' '+a.zip) as "addr3",
   b.payorname as "payor"
FROM
   sos.rv_patients a 
   join sos.rv_policies b on a.ptnum = b.ptnum
WHERE
   a.flag = 0 
   and a.priprvcode='prv' 
   and (b.payorname like '%magellan%' or b.payorname like '%ubh%') 
   and (b.active is null or b.active <= current date) 
   and (b.inactive is null or b.inactive >= current date)
; output to c:\sos\labels.csv format ascii
The resulting csv file can be loaded into Excel for additional manipulation, if you like, or can be used as
is. If you check the help in Word regarding mailing labels, that should take you the rest of the way. Oh,
note the fourth line up from the bottom. This one is where I am specifying the payor names. If you have
a UBH payor that you have spelled out as "United Behavioral Health" you should add another "or...." to
that condition, or change the '%ubh%' condition. This expression means that it will include payors with
the characters "ubh" anywhere in the name. That could result in some payors you do not want, such as a
payor named "Flubhead" or something like that. You should be able to fine tune that with a little
experimentation. On the fifth line up from the bottom you must replace 'prv' with your psychiatrist's
provider code. The other conditions restrict the output to active patients with active matching policies as
of today's date.