Checking for Fields that Should Be Included in Encounter Import

The following query generates an HTML report that indicates the field elements that should be considered for inclusion if you are planning to import encounter data from a third-party product for billing by SOS Office Manager. The previous year of charge entries are analyzed.

Select 'Total Charge Count',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365)
UNION
Select 'CSU = U',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365) and csutype = 'u'
UNION
Select 'CSU = N',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365) and csutype = 'n'
UNION
Select 'Date Range',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365) and coalesce(startdate,trandate) <> trandate
UNION
Select 'Units <> 1',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365) and units <> 1
UNION
Select 'Cost',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365) and coalesce(cost,0) <> 0
UNION
Select 'CPT Modifiers',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365) and coalesce(cptmod1,'')+coalesce(cptmod2,'')+coalesce(cptmod3,'')+coalesce(cptmod4,'') <> ''
UNION
Select 'Non-default POS',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365) and poscodenum <> (select lastpos from sos.ptvars where ptnum = journal.ptnum)
UNION
Select 'FP',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365) and coalesce(fp,'') <> ''
UNION
Select 'EMG',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365) and coalesce(emergency,'') <> ''
UNION
Select 'COB',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365) and coalesce(cob,'') <> ''
UNION
Select 'Box 24K',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365) and coalesce(box24k,'') <> ''
UNION
Select 'Lab Charge',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365) and coalesce(labchg,0) <> 0
UNION
Select 'SortCode',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365) and coalesce(sortcode,0) <> 0
UNION
Select 'Comment1',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365) and coalesce(comment1,'') <> ''
UNION
Select 'Comment2',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365) and coalesce(comment2,'') <> ''
UNION
Select 'Remark',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365) and coalesce(remark,'') <> ''
UNION
Select 'Memo',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365) and coalesce(memo,'') <> ''
UNION
Select 'MemoHA0',count(*) from sos.journal join sos.jcharges where trandate > (today() - 365) and coalesce(memoisha0,0) <> 0
;
OUTPUT TO 'c:\sos\ChargeImportCheck.html' format html

 

Expiring Authorizations by Primary Provider

I don’t know about other people but, I could really use query to provide a simple table of PA’s that are
nearly exhausted. The MC auth report is just too big.

Criteria is simply PAs < given_number and Exp Date between given_dates

Output like:

Provider | Patient | PAs Remaining | Exp.Date

sorted by provider, patient

I added a couple of refinements, including a column for the insurer’s name, and both the primary
provider and authorized provider. You can change the ORDER BY to reflect the one you want. I also
tuned up the conditions in the WHERE clause to eliminate inactive/discharged patients and inactive
authorizations, and included the expiration date in the selection conditions (third to last line). The
“TODAY() + 14” in this example means that auths with expiration dates within the next 14 days will be
selected. Obviously, the “3” in the same line selects auths with less than 3 visits remaining.

SELECT
   f.provcode AS "PrimaryProvider",
   g.provcode AS "AuthorizedProvider",
   (e.lastname + ', ' + e.firstname + ' / ' + e.id) AS "Patient",
   d.payorname AS "Insurer",
   (a.maxvisits - a.usedvisits) AS "VisitsLeft",
   a.enddate AS "ExpDate"
FROM
   sos.ptauths a
   JOIN sos.ptpolicies b ON a.ptpolnum = b.ptpolnum
   JOIN sos.ptpayors c ON b.ptpayornum = c.ptpayornum
   JOIN sos.payors d ON c.payornum = d.payornum
   JOIN sos.patients e ON a.ptnum = e.ptnum
   LEFT OUTER JOIN sos.providers f ON e.providernum = f.providernum
   LEFT OUTER JOIN sos.providers g ON a.providernum = g.providernum
WHERE
   a.status = 'A' //active auths only
   AND e.flag = 0 //active patients only
   AND e.dischargedate is null // no discharge date entered
   AND ("VisitsLeft" < 3 OR "ExpDate" < TODAY() + 14)
ORDER BY
   "PrimaryProvider", 
   "Patient"

List Patients with No Primary Diagnosis by Primary Provider

This is a relatively easy query that can be used to generate a list of patients for which no diagnosis has
been entered. Technically, the selection is for a missing Dx1, so if for some reason there is no Dx1, but
there is a Dx entered in Dx2, 3, or 4 the name will still appear on the list.

Note that we use LEFT OUTER JOINs between the Patients table and the Providers and PtCSU tables
so that if there is no primary provider entered, or the default claim setup is missing for some reason, we
will still see the patient name in the result set. Also notice the OR condition in the WHERE clause. Here
we are looking for a missing Dx link (null) or a link number of zero (which is what it should be if no Dx
has been selected). It is ALWAYS a good idea to put your OR expressions within parentheses so that the
query parser does not make it’s own decision about this matter. Here it would not really matter because
there is no ambiguity, but it is still a good habit and one that will save you much confusion when your
conditions are more complex.

SELECT
   Providers.ProvCode,
   Providers.ProvLName, 
   Providers.ProvFName,
   Patients.LastName, 
   Patients.FirstName, 
   Patients.ID
FROM
   sos.Patients
   LEFT OUTER JOIN sos.Providers ON Patients.ProviderNum = Providers.ProviderNum
   LEFT OUTER JOIN sos.PtCSU ON Patients.PtNum = PtCSU.PtNum
WHERE
   Patients.LicNum = 101 
   AND Patients.Flag = 0 
   AND PtCSU.TypeFlag = 'D' 
   AND (PtCSU.Dx1 IS NULL OR PtCSU.Dx1 = 0)
ORDER BY
   Providers.ProvCode,
   Patients.LastName, 
   Patients.FirstName,Patients.ID

Patient Count for Period by SortCode

This one is a variation on other, earlier queries. The difference here is the introduction of SortCode. SortCode is a value specified when entering charges and credits. In order to associate patients with particular SortCode values, we must inspect the transactions linked to the patient and to the SortCode.

If you were to inspect the values in the sortcode field of the journal table, you would see only numbers that do not reflect your selections in the SortCode field in the transaction entry windows. The number is a link to a row in the lookups table that contains the SortCode shorthand code and description. You must, therefore, include a JOIN from journal.sortcode to lookups.lunum, which is the analogous value in the lookups table.

The aggregate function structure COUNT(DISTINCT PTNUM) forces the query to count only unique
patients, eliminating duplicates. If you were to omit the keyword DISTINCT, you would end up with a
count of the number of transactions instead of the number of unique patients. Note that the query returns only charge entries (a.trantype = ‘S’) because we want to count only patients who have been seen during the period. We don’t want to count payments or adjustments (which share a trantype of ‘P’).

This example also uses a standard function to represent the current date, TODAY(*). An alternate syntax would simply be the words CURRENT DATE. The result would be identical. You could, of course, also substitute a specific date.

One more thing: note that if there are transactions for the same patient but that have different
SortCodes, the patient will appear in the count for each of the SortCodes linked to his or her charge
entries.

Here is the query:

SELECT
   lucode AS "SortCode", 
   COUNT(DISTINCT PTNUM) AS "ClientCount"
FROM
   sos.journal a
   JOIN sos.lookups b ON a.sortcode = b.lunum
WHERE
   a.trantype = 'S'
   AND a.trandate BETWEEN '2005-10-01' AND TODAY(*)
GROUP BY
   "SortCode"
ORDER BY
   "SortCode"

Active Patient Count For Date Range

This simple query tells you how many patients have charge entries in their ledgers between two dates.
The keyword DISTINCT in the COUNT() function eliminates duplicates.

SELECT
   COUNT(DISTINCT ptnum)
FROM
   sos.journal
WHERE
   trantype = 'S'
   AND amount > 0
   AND trandate BETWEEN '2004-01-01' AND '2004-12-31'

Here’s a variation using the rv_charges view that breaks down the patient count by rendering provider. In
this case, we use rv_charges as an easy way to get to the provider code associated with the charges:

SELECT
   provcode AS "Provider", 
   COUNT(DISTINCT ptnum) AS "Clients Seen"
FROM
   sos.rv_charges
WHERE
   amount > 0
   AND trandate BETWEEN '2004-01-01' AND '2004-12-31'
GROUP BY
   provcode